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
|
||||
.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.IOException;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
@ -39,6 +40,16 @@ public class ApsAppJsonTranslator extends ApsOrganizationHandler implements ApsF
|
||||
boolean changed = false;
|
||||
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")) {
|
||||
ObjectNode jsonModel = (ObjectNode)_jsonModel;
|
||||
|
||||
@ -77,8 +88,42 @@ public class ApsAppJsonTranslator extends ApsOrganizationHandler implements ApsF
|
||||
// changed = true;
|
||||
}
|
||||
|
||||
for (JsonNode _jsonIdentityInfo : descriptor.get("definition").get("publishIdentityInfo")) {
|
||||
ObjectNode jsonGroup = (ObjectNode)_jsonIdentityInfo.get("group");
|
||||
return changed;
|
||||
}
|
||||
|
||||
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 identityType = jsonIdentityInfo.get("type").asText();
|
||||
if (identityType == null) {
|
||||
this.logger.warn("Found identity with no type; ignoring ...");
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (identityType.toLowerCase()) {
|
||||
case "user":
|
||||
this.logger.warn("Found 'user' identity, which should never be used for portablility; removing ...");
|
||||
changed = true;
|
||||
i.remove();
|
||||
break;
|
||||
case "group":
|
||||
changed = this.translateGroup(jsonIdentityInfo) || changed;
|
||||
break;
|
||||
default:
|
||||
this.logger.warn("Found '{}' identity, which is not expected; ignoring ...", identityType);
|
||||
}
|
||||
}
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
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);
|
||||
@ -112,10 +157,8 @@ public class ApsAppJsonTranslator extends ApsOrganizationHandler implements ApsF
|
||||
this.logger.warn("The organization '{}' does not exist in APS", fileOrgName);
|
||||
// FIXME create the organization
|
||||
}
|
||||
}
|
||||
|
||||
if (changed)
|
||||
ModelUtil.getInstance().writeJson(descriptor, file, false);
|
||||
return changed;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user