}catch(Exception e) {
}
Worksheet worksheet = workspace.getWorksheet(worksheetId);
SuperSelection selection = getSuperSelection(worksheet);
OntologyManager ontMgr = workspace.getOntologyManager();
String alignmentId = AlignmentManager.Instance().constructAlignmentId(workspace.getId(), worksheetId);
Alignment alignment = AlignmentManager.Instance().getAlignment(alignmentId);
if (alignment == null) {
alignment = new Alignment(ontMgr);
AlignmentManager.Instance().addAlignmentToMap(alignmentId, alignment);
}
// Save the original alignment for undo
oldAlignment = alignment.getAlignmentClone();
oldGraph = (DirectedWeightedMultigraph<Node, DefaultLink>)alignment.getGraph().clone();
/*** Add the appropriate nodes and links in alignment graph ***/
List<SemanticType> typesList = new ArrayList<SemanticType>();
for (int i = 0; i < typesArr.length(); i++) {
try {
LabeledLink newLink = null;
JSONObject type = typesArr.getJSONObject(i);
String domainValue;
// For property semantic types, domain uri goes to "domainValue" and link uri goes to "fullTypeValue".
// For class semantic type, class uri goes "fullTypeValue" and "domainValue" is empty.
if(type.has(ClientJsonKeys.DomainId.name()))
domainValue = type.getString(ClientJsonKeys.DomainId.name());
else
domainValue = type.getString("Domain"); //For backward compatibility to older models
String fullTypeValue = type.getString(ClientJsonKeys.FullType.name());
// logger.trace("FULL TYPE:" + type.getString(ClientJsonKeys.FullType.name()));
// logger.trace("Domain: " + type.getString(ClientJsonKeys.Domain.name()));
// Look if the domain value exists. If it exists, then it is a domain of a data property. If not
// then the value in FullType has the the value which indicates if a new class instance is needed
// or an existing class instance should be used (this is the case when just the class is chosen as a sem type).
// Label domainName = null;
boolean isClassSemanticType = false;
boolean semanticTypeAlreadyExists = false;
Node domain = null;
String domainUriOrId;
Label linkLabel;
// if domain value is empty, semantic type is a class semantic type
if (domainValue.equals("")) {
isClassSemanticType = true;
domainUriOrId = fullTypeValue;
linkLabel = ClassInstanceLink.getFixedLabel();
} else {
isClassSemanticType = false;
domainUriOrId = domainValue;
linkLabel = ontMgr.getUriLabel(fullTypeValue);
if (linkLabel == null) {
logger.error("URI/ID does not exist in the ontology or model: " + fullTypeValue);
continue;
}
}
if(domainUriOrId.endsWith(" (add)"))
domainUriOrId = domainUriOrId.substring(0, domainUriOrId.length()-5).trim();
domain = alignment.getNodeById(domainUriOrId);
logger.info("Got domain for domainUriOrId:" + domainUriOrId + " ::" + domain);
if (domain == null) {
Label label = ontMgr.getUriLabel(domainUriOrId);
// if (label == null) {
// logger.error("URI/ID does not exist in the ontology or model: " + domainUriOrId);
// continue;
// }
if (label == null) {
if(type.has(ClientJsonKeys.DomainUri.name())) {
label = new Label(type.getString(ClientJsonKeys.DomainUri.name()));
} else {
//This part of the code is for backward compatibility. Newer models should have domainUri
int len = domainValue.length();
if ((len > 1) && Character.isDigit(domainValue.charAt(len-1))) {
String newDomainValue = domainValue.substring(0, len-1);
label = ontMgr.getUriLabel(newDomainValue);
}
if (label == null) {
logger.error("No graph node found for the node: " + domainValue);
return new UpdateContainer(new ErrorUpdate("" +
"Error occured while setting semantic type!"));