Skip to content

Commit

Permalink
RAP-46 Fixed the issue that the Identifier snapshot + full file fails…
Browse files Browse the repository at this point in the history
… to update
  • Loading branch information
QuyenLy87 committed Mar 16, 2024
1 parent 8762fc2 commit 3c2fb62
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ public void exportDelta(RF2TableResults tableResults, TableSchema tableSchema, O
String languageRefsetId = null;
if (ComponentType.IDENTIFIER.equals(tableSchema.getComponentType())) {
lineParts = line.split(RF2Constants.COLUMN_SEPARATOR, 6);
// effective time is on the second column
currentId = lineParts[0] + lineParts[4];
currentId = lineParts[0] + RF2Constants.COLUMN_SEPARATOR + lineParts[1];
// Replace the composite key by identifierSchemeId
line = line.replace(currentId, lineParts[0]);
} else {
if (Pattern.compile(RF2Constants.LANGUAGE_FILE_PATTERN).matcher(tableSchema.getFilename()).matches()) {
lineParts = line.split(RF2Constants.COLUMN_SEPARATOR, 6);
Expand All @@ -54,12 +55,11 @@ public void exportDelta(RF2TableResults tableResults, TableSchema tableSchema, O
lineParts = line.split(RF2Constants.COLUMN_SEPARATOR, 3);
}
currentId = lineParts[0];
}
if ((tableSchema.getFilename().contains(RF2Constants.REFERENCE_SET_DESCRIPTOR_FILE_IDENTIFIER) && this.excludeRefsetDescriptorMembers != null && this.excludeRefsetDescriptorMembers.contains(currentId))
|| (this.excludeLanguageRefsetIds != null && languageRefsetId != null && excludeLanguageRefsetIds.contains(languageRefsetId))) {
continue;
}

if (isRF2LineExcluded(tableSchema, currentId, languageRefsetId)) {
continue;
}
}
deltaWriter.append(line);
deltaWriter.append(RF2Constants.LINE_ENDING);
}
Expand Down Expand Up @@ -98,9 +98,11 @@ public void exportFullAndSnapshot(RF2TableResults tableResults, TableSchema sche
String languageRefsetId = null;
if (ComponentType.IDENTIFIER.equals(schema.getComponentType())) {
lineParts = currentLine.split(RF2Constants.COLUMN_SEPARATOR, 6);
// effective time is on the second column
currentId = lineParts[0] + lineParts[4];
currentEffectiveTimeInt = Integer.parseInt(lineParts[1]);
currentId = lineParts[0] + RF2Constants.COLUMN_SEPARATOR + lineParts[1];
// effective time is on the third column
currentEffectiveTimeInt = Integer.parseInt(lineParts[2]);
// Replace the composite key by identifierSchemeId
currentLine = currentLine.replace(currentId, lineParts[0]);
} else {
if (Pattern.compile(RF2Constants.LANGUAGE_FILE_PATTERN).matcher(schema.getFilename()).matches()) {
lineParts = currentLine.split(RF2Constants.COLUMN_SEPARATOR, 6);
Expand All @@ -110,11 +112,12 @@ public void exportFullAndSnapshot(RF2TableResults tableResults, TableSchema sche
}

currentId = lineParts[0];
// effective time is on the second column
currentEffectiveTimeInt = Integer.parseInt(lineParts[1]);
}
if ((schema.getFilename().contains(RF2Constants.REFERENCE_SET_DESCRIPTOR_FILE_IDENTIFIER) && this.excludeRefsetDescriptorMembers != null && this.excludeRefsetDescriptorMembers.contains(currentId))
|| (this.excludeLanguageRefsetIds != null && languageRefsetId != null && excludeLanguageRefsetIds.contains(languageRefsetId))) {
continue;

if (isRF2LineExcluded(schema, currentId, languageRefsetId)) {
continue;
}
}

// Write to Full file
Expand Down Expand Up @@ -163,6 +166,11 @@ public void exportFull(RF2TableResults results, TableSchema tableSchema, OutputS
}
}

private boolean isRF2LineExcluded(TableSchema tableSchema, String currentId, String languageRefsetId) {
return (tableSchema.getFilename().contains(RF2Constants.REFERENCE_SET_DESCRIPTOR_FILE_IDENTIFIER) && this.excludeRefsetDescriptorMembers != null && this.excludeRefsetDescriptorMembers.contains(currentId))
|| (this.excludeLanguageRefsetIds != null && languageRefsetId != null && excludeLanguageRefsetIds.contains(languageRefsetId));
}

private String productHeader(List<Field> fields) {
StringBuilder producter = new StringBuilder();
boolean firstField = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ private void insertData(final BufferedReader reader, final TableSchema tableSche
// skip data from previous release
continue;
}
key = tableSchema.getComponentType() == ComponentType.IDENTIFIER ? new StringKey(parts[0], parts[1]) : getKey(parts[0], parts[1]);
key = tableSchema.getComponentType() == ComponentType.IDENTIFIER ? getIdentifierCompositeKey(line) : getKey(parts[0], parts[1]);
if (workbenchDataFixesRequired && deltaData && tableSchema.getComponentType() == ComponentType.REFSET) {
// Get refset id
refsetIdMatcher = REFSET_ID_PATTERN.matcher(line);
Expand Down Expand Up @@ -317,6 +317,11 @@ private String getCompositeKey(final Pattern keyPattern, final String line) thro
}
}

private Key getIdentifierCompositeKey(final String line) {
String[] parts = line.split(RF2Constants.COLUMN_SEPARATOR, 6);
return new StringKey(parts[0] + RF2Constants.COLUMN_SEPARATOR + parts[4], parts[1]);
}

private Key getKey(final String part0, final String part1) {
Key key;
if (idType == DataType.SCTID) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ public int compareTo(Key other) {
} else {
StringKey otherStringKey = (StringKey) other;
result = compKey.compareTo(otherStringKey.compKey);
if (result == 0 && effectiveTime != null) {
result = effectiveTime.compareTo(other.getDate());
}
}
return result;
}
Expand All @@ -44,16 +47,35 @@ public String toString() {

@Override
public boolean equals(Object obj) {
if (obj instanceof StringKey objStringKey) {
return compKey.equals(objStringKey.compKey);
} else {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
StringKey other = (StringKey) obj;
if (effectiveTime == null) {
if (other.getDate() != null) {
return false;
}
} else if (!effectiveTime.equals(other.getDate())) {
return false;
}
if (compKey == null) {
return other.getIdString() == null;
} else return compKey.equals(other.getIdString());
}

@Override
public int hashCode() {
return compKey.hashCode();
final int prime = 31;
int result = 1;
result = prime * result + ((effectiveTime == null) ? 0 : effectiveTime.hashCode());
result = prime * result + ((compKey == null) ? 0 : compKey.hashCode());
return result;
}

}

0 comments on commit 3c2fb62

Please sign in to comment.