Skip to content

Commit

Permalink
CLDR-15161 progress: back end for locale completion (third meter) (#1638
Browse files Browse the repository at this point in the history
)

- back end API for LocaleCompletion
- test case for LocaleCompletion, including minor changes to enable
  testability of STFactory-related code.
- update launch.json to improve attaching to OpenLiberty
- return 503 error if the SurveyTool is not yet started
- Ignore some paths per Phase and SubmissionLocales
  • Loading branch information
srl295 authored Dec 13, 2021
1 parent 8334c30 commit 686de2b
Show file tree
Hide file tree
Showing 9 changed files with 562 additions and 104 deletions.
14 changes: 11 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,16 @@
{
"type": "java",
"request": "attach",
"name": "Attach by Process ID",
"processId": "${command:PickJavaProcess}"
"name": "Attach cldr-apps by Process ID",
"processId": "${command:PickJavaProcess}",
"projectName": "cldr-apps"
},
{
"type": "java",
"request": "attach",
"name": "Attach cldr-code by Process ID",
"processId": "${command:PickJavaProcess}",
"projectName": "cldr-code"
}
]
}
}
2 changes: 1 addition & 1 deletion tools/cldr-apps/js/src/esm/cldrProgress.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { notification } from "ant-design-vue";

const USE_NEW_PROGRESS_WIDGET = true;
const CAN_GET_VOTER_PROGRESS = true;
const CAN_GET_LOCALE_PROGRESS = false; // For now
const CAN_GET_LOCALE_PROGRESS = false;

let progressWrapper = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,16 @@ public File getAnnotationsDir() {
* @author srl
*
*/
private static class ScratchXMLSource extends XMLSource {
ScratchXMLSource(String id) {
public static class ScratchXMLSource extends XMLSource {
public ScratchXMLSource(String id) {
super.setLocaleID(id);
super.setInitialComment("GENERATED FILE\n"
+ "Note- This is a sandbox (scratch) locale.\n"+
"It is not a part of the CLDR release.\nDo not modify it, and especially do not"
+ " check it in to the CLDR source repository.\n\nThis notice generated by SandboxLocales.java");
}
Map<String, String> valueMap = CldrUtility.newConcurrentHashMap();
Map<String, String> fullPathMap = CldrUtility.newConcurrentHashMap();
private Comments comments = new Comments();

@Override
Expand All @@ -108,7 +109,11 @@ public XMLSource freeze() {
@Override
public void putFullPathAtDPath(String distinguishingXPath,
String fullxpath) {
throw new RuntimeException("not implemented");
if (distinguishingXPath.equals(fullxpath)) {
fullPathMap.remove(distinguishingXPath);
} else {
fullPathMap.put(distinguishingXPath, fullxpath);
}
}

@Override
Expand All @@ -118,7 +123,7 @@ public void putValueAtDPath(String distinguishingXPath, String value) {

@Override
public void removeValueAtDPath(String distinguishingXPath) {
throw new RuntimeException("not implemented");
valueMap.remove(distinguishingXPath);
}

@Override
Expand All @@ -128,7 +133,12 @@ public String getValueAtDPath(String path) {

@Override
public String getFullPathAtDPath(String path) {
throw new RuntimeException("not implemented");
final String fullxpath = fullPathMap.get(path);
if (fullxpath == null) {
return path;
} else {
return fullxpath;
}
}

@Override
Expand All @@ -149,7 +159,14 @@ public Iterator<String> iterator() {
@Override
public void getPathsWithValue(String valueToMatch, String pathPrefix,
Set<String> result) {
throw new RuntimeException("not implemented");
for(final String xpath : this) {
if (!xpath.startsWith(pathPrefix)) {
continue;
}
if (valueToMatch.equals(getValueAtDPath(xpath))) {
result.add(xpath);
}
}
}
}

Expand All @@ -162,4 +179,4 @@ public Factory getFactory(File commonMain) {
File dirs[] = { getMainDir(), getAnnotationsDir(), commonMain };
return SimpleFactory.make(dirs, ".*");
}
}
}
68 changes: 34 additions & 34 deletions tools/cldr-apps/src/main/java/org/unicode/cldr/web/STFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -637,39 +637,6 @@ public final Stamp getStamp() {
return stamp;
}

/**
* Get the Status for the given CLDRFile, path, and value.
*
* @param cldrFile
* @param path
* @param value
* @return the Status
*/
private Status getStatus(CLDRFile cldrFile, String path, final String value) {
String fullXPath = cldrFile.getFullXPath(path);
if (fullXPath == null) {
fullXPath = path;
}
XPathParts xpp = XPathParts.getFrozenInstance(fullXPath);
String draft = xpp.getAttributeValue(-1, LDMLConstants.DRAFT);
Status status = draft == null ? Status.approved : VoteResolver.Status.fromString(draft);

/*
* Reset to missing if the value is inherited from root or code-fallback, unless the XML actually
* contains INHERITANCE_MARKER. Pass false for skipInheritanceMarker so that status will not be
* missing for explicit INHERITANCE_MARKER. Reference: https://unicode.org/cldr/trac/ticket/11857
*/
final String srcid = cldrFile.getSourceLocaleIdExtended(path, null, false /* skipInheritanceMarker */);
if (srcid.equals(XMLSource.CODE_FALLBACK_ID)) {
status = Status.missing;
} else if (srcid.equals("root")) {
if (!srcid.equals(diskFile.getLocaleID())) {
status = Status.missing;
}
}
return status;
}

/**
*
* @param user
Expand Down Expand Up @@ -960,7 +927,7 @@ private VoteResolver<String> getResolverInternal(PerXPathData perXPathData, Stri

// set current Trunk (baseline) value (if present)
final String currentValue = diskData.getValueAtDPath(path);
final Status currentStatus = getStatus(diskFile, path, currentValue);
final Status currentStatus = calculateStatus(diskFile, diskFile, path);
if (ERRORS_ALLOWED_IN_VETTING || vc.canUseValue(currentValue)) {
r.setBaseline(currentValue, currentStatus);
r.add(currentValue);
Expand Down Expand Up @@ -2344,4 +2311,37 @@ public static final String getLastVoteTable() {
final String dbName = DBUtils.Table.VOTE_VALUE.forVersion(SurveyMain.getLastVoteVersion(), false).toString();
return dbName;
}

/**
* Utility function to calculate CLDRFile.Status
* @param cldrFile the CLDR File to use
* @param diskFile the 'baseline' file to use
* @param path xpath
* @param value current string value
* @return
*/
public static final Status calculateStatus(CLDRFile cldrFile, CLDRFile diskFile, String path) {
String fullXPath = cldrFile.getFullXPath(path);
if (fullXPath == null) {
fullXPath = path;
}
XPathParts xpp = XPathParts.getFrozenInstance(fullXPath);
String draft = xpp.getAttributeValue(-1, LDMLConstants.DRAFT);
Status status = draft == null ? Status.approved : VoteResolver.Status.fromString(draft);

/*
* Reset to missing if the value is inherited from root or code-fallback, unless the XML actually
* contains INHERITANCE_MARKER. Pass false for skipInheritanceMarker so that status will not be
* missing for explicit INHERITANCE_MARKER. Reference: https://unicode.org/cldr/trac/ticket/11857
*/
final String srcid = cldrFile.getSourceLocaleIdExtended(path, null, false /* skipInheritanceMarker */);
if (srcid.equals(XMLSource.CODE_FALLBACK_ID)) {
status = Status.missing;
} else if (srcid.equals("root")) {
if (!srcid.equals(diskFile.getLocaleID())) {
status = Status.missing;
}
}
return status;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -985,7 +985,10 @@ public UserRegistry.User getEmptyUser() {

static SurveyMain sm = null; // static for static checking of defaultContent

private UserRegistry() {
/**
* Public for tests
*/
public UserRegistry() {
}

// ------- special things for "list" mode:
Expand Down
Loading

0 comments on commit 686de2b

Please sign in to comment.