fixed user-based translation
This commit is contained in:
parent
17594dc520
commit
dd9d5735bf
3
.gitignore
vendored
3
.gitignore
vendored
@ -7,3 +7,6 @@ pom.xml.versionsBackup
|
|||||||
.project
|
.project
|
||||||
.classpath
|
.classpath
|
||||||
|
|
||||||
|
# Codegen
|
||||||
|
.apt_generated
|
||||||
|
.apt_generated_tests
|
||||||
|
@ -2,6 +2,7 @@ package com.inteligr8.maven.aps.modeling.translator;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@ -39,6 +40,16 @@ public class ApsAppJsonTranslator extends ApsOrganizationHandler implements ApsF
|
|||||||
boolean changed = false;
|
boolean changed = false;
|
||||||
JsonNode descriptor = ModelUtil.getInstance().readJson(file);
|
JsonNode descriptor = ModelUtil.getInstance().readJson(file);
|
||||||
|
|
||||||
|
changed = this.translateModels(descriptor) || changed;
|
||||||
|
changed = this.translateIdentities(descriptor) || changed;
|
||||||
|
|
||||||
|
if (changed)
|
||||||
|
ModelUtil.getInstance().writeJson(descriptor, file, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean translateModels(JsonNode descriptor) {
|
||||||
|
boolean changed = false;
|
||||||
|
|
||||||
for (JsonNode _jsonModel : descriptor.get("definition").get("models")) {
|
for (JsonNode _jsonModel : descriptor.get("definition").get("models")) {
|
||||||
ObjectNode jsonModel = (ObjectNode)_jsonModel;
|
ObjectNode jsonModel = (ObjectNode)_jsonModel;
|
||||||
|
|
||||||
@ -77,45 +88,77 @@ public class ApsAppJsonTranslator extends ApsOrganizationHandler implements ApsF
|
|||||||
// changed = true;
|
// changed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (JsonNode _jsonIdentityInfo : descriptor.get("definition").get("publishIdentityInfo")) {
|
return changed;
|
||||||
ObjectNode jsonGroup = (ObjectNode)_jsonIdentityInfo.get("group");
|
}
|
||||||
|
|
||||||
|
private boolean translateIdentities(JsonNode descriptor) {
|
||||||
|
boolean changed = false;
|
||||||
|
|
||||||
|
Iterator<JsonNode> i = descriptor.get("definition").get("publishIdentityInfo").iterator();
|
||||||
|
while (i.hasNext()) {
|
||||||
|
JsonNode jsonIdentityInfo = i.next();
|
||||||
|
|
||||||
String fileOrgName = jsonGroup.get("name").asText();
|
String identityType = jsonIdentityInfo.get("type").asText();
|
||||||
this.logger.trace("Found organization '{}' in APS App descriptor", fileOrgName);
|
if (identityType == null) {
|
||||||
|
this.logger.warn("Found identity with no type; ignoring ...");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (this.apsOrgIndex.containsKey(fileOrgName)) {
|
switch (identityType.toLowerCase()) {
|
||||||
long fileOrgId = jsonGroup.get("id").asLong();
|
case "user":
|
||||||
GroupLight apsOrg = this.apsOrgIndex.get(fileOrgName);
|
this.logger.warn("Found 'user' identity, which should never be used for portablility; removing ...");
|
||||||
|
|
||||||
if (apsOrg == null) {
|
|
||||||
this.logger.debug("The organization '{}' does not exist in APS; adding to APS", fileOrgName);
|
|
||||||
long apsGroupId = this.createOrganization(fileOrgName);
|
|
||||||
jsonGroup.put("id", apsGroupId);
|
|
||||||
changed = true;
|
changed = true;
|
||||||
} else if (fileOrgId != apsOrg.getId()) {
|
i.remove();
|
||||||
this.logger.debug("The organization '{}' exists in APS with ID {}; changing descriptor", fileOrgName, apsOrg.getId());
|
break;
|
||||||
jsonGroup.put("id", apsOrg.getId());
|
case "group":
|
||||||
changed = true;
|
changed = this.translateGroup(jsonIdentityInfo) || changed;
|
||||||
} else {
|
break;
|
||||||
this.logger.trace("The organization '{}' ID does not change; leaving unchanged", fileOrgName);
|
default:
|
||||||
}
|
this.logger.warn("Found '{}' identity, which is not expected; ignoring ...", identityType);
|
||||||
|
|
||||||
if (jsonGroup.has("parentGroupId")) {
|
|
||||||
jsonGroup.put("parentGroupId", 0);
|
|
||||||
changed = true;
|
|
||||||
}
|
|
||||||
// if (jsonGroup.has("parentGroupId")) {
|
|
||||||
// jsonGroup.remove("parentGroupId");
|
|
||||||
// changed = true;
|
|
||||||
// }
|
|
||||||
} else {
|
|
||||||
this.logger.warn("The organization '{}' does not exist in APS", fileOrgName);
|
|
||||||
// FIXME create the organization
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (changed)
|
return changed;
|
||||||
ModelUtil.getInstance().writeJson(descriptor, file, false);
|
}
|
||||||
|
|
||||||
|
private boolean translateGroup(JsonNode jsonIdentityInfo) {
|
||||||
|
boolean changed = false;
|
||||||
|
ObjectNode jsonGroup = (ObjectNode)jsonIdentityInfo.get("group");
|
||||||
|
|
||||||
|
String fileOrgName = jsonGroup.get("name").asText();
|
||||||
|
this.logger.trace("Found organization '{}' in APS App descriptor", fileOrgName);
|
||||||
|
|
||||||
|
if (this.apsOrgIndex.containsKey(fileOrgName)) {
|
||||||
|
long fileOrgId = jsonGroup.get("id").asLong();
|
||||||
|
GroupLight apsOrg = this.apsOrgIndex.get(fileOrgName);
|
||||||
|
|
||||||
|
if (apsOrg == null) {
|
||||||
|
this.logger.debug("The organization '{}' does not exist in APS; adding to APS", fileOrgName);
|
||||||
|
long apsGroupId = this.createOrganization(fileOrgName);
|
||||||
|
jsonGroup.put("id", apsGroupId);
|
||||||
|
changed = true;
|
||||||
|
} else if (fileOrgId != apsOrg.getId()) {
|
||||||
|
this.logger.debug("The organization '{}' exists in APS with ID {}; changing descriptor", fileOrgName, apsOrg.getId());
|
||||||
|
jsonGroup.put("id", apsOrg.getId());
|
||||||
|
changed = true;
|
||||||
|
} else {
|
||||||
|
this.logger.trace("The organization '{}' ID does not change; leaving unchanged", fileOrgName);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (jsonGroup.has("parentGroupId")) {
|
||||||
|
jsonGroup.put("parentGroupId", 0);
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
// if (jsonGroup.has("parentGroupId")) {
|
||||||
|
// jsonGroup.remove("parentGroupId");
|
||||||
|
// changed = true;
|
||||||
|
// }
|
||||||
|
} else {
|
||||||
|
this.logger.warn("The organization '{}' does not exist in APS", fileOrgName);
|
||||||
|
// FIXME create the organization
|
||||||
|
}
|
||||||
|
|
||||||
|
return changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user