use of com.runwaysdk.system.metadata.MdAttributeConcrete in project geoprism-registry by terraframe.
the class ListTypeVersion method createMdAttributeFromAttributeType.
protected static void createMdAttributeFromAttributeType(TableMetadata metadata, AttributeType attributeType, ServerGeoObjectType type, Collection<Locale> locales) {
MdBusiness mdBusiness = metadata.getMdBusiness();
if (!(attributeType instanceof AttributeTermType || attributeType instanceof AttributeClassificationType || attributeType instanceof AttributeLocalType)) {
MdAttributeConcrete mdAttribute = null;
if (attributeType.getType().equals(AttributeCharacterType.TYPE)) {
mdAttribute = new MdAttributeCharacter();
MdAttributeCharacter mdAttributeCharacter = (MdAttributeCharacter) mdAttribute;
mdAttributeCharacter.setDatabaseSize(MdAttributeCharacterInfo.MAX_CHARACTER_SIZE);
} else if (attributeType.getType().equals(AttributeDateType.TYPE)) {
mdAttribute = new MdAttributeDateTime();
} else if (attributeType.getType().equals(AttributeIntegerType.TYPE)) {
mdAttribute = new MdAttributeLong();
} else if (attributeType.getType().equals(AttributeFloatType.TYPE)) {
AttributeFloatType attributeFloatType = (AttributeFloatType) attributeType;
mdAttribute = new MdAttributeDouble();
mdAttribute.setValue(MdAttributeDoubleInfo.LENGTH, Integer.toString(attributeFloatType.getPrecision()));
mdAttribute.setValue(MdAttributeDoubleInfo.DECIMAL, Integer.toString(attributeFloatType.getScale()));
} else if (attributeType.getType().equals(AttributeBooleanType.TYPE)) {
mdAttribute = new MdAttributeBoolean();
} else {
throw new UnsupportedOperationException("Unsupported type [" + attributeType.getType() + "]");
}
mdAttribute.setAttributeName(attributeType.getName());
LocalizedValueConverter.populate(mdAttribute.getDisplayLabel(), attributeType.getLabel());
LocalizedValueConverter.populate(mdAttribute.getDescription(), attributeType.getDescription());
mdAttribute.setDefiningMdClass(mdBusiness);
mdAttribute.apply();
} else if (attributeType instanceof AttributeTermType || attributeType instanceof AttributeClassificationType) {
MdAttributeCharacter cloneAttribute = new MdAttributeCharacter();
cloneAttribute.setValue(MdAttributeConcreteInfo.NAME, attributeType.getName());
cloneAttribute.setValue(MdAttributeCharacterInfo.SIZE, "255");
cloneAttribute.addIndexType(MdAttributeIndices.NON_UNIQUE_INDEX);
LocalizedValueConverter.populate(cloneAttribute.getDisplayLabel(), attributeType.getLabel());
LocalizedValueConverter.populate(cloneAttribute.getDescription(), attributeType.getDescription());
cloneAttribute.setDefiningMdClass(mdBusiness);
cloneAttribute.apply();
metadata.addPair(cloneAttribute, cloneAttribute);
MdAttributeCharacter mdAttributeDefaultLocale = new MdAttributeCharacter();
mdAttributeDefaultLocale.setValue(MdAttributeCharacterInfo.NAME, attributeType.getName() + DEFAULT_LOCALE);
mdAttributeDefaultLocale.setValue(MdAttributeCharacterInfo.SIZE, "255");
mdAttributeDefaultLocale.setDefiningMdClass(mdBusiness);
LocalizedValueConverter.populate(mdAttributeDefaultLocale.getDisplayLabel(), attributeType.getLabel(), " (defaultLocale)");
LocalizedValueConverter.populate(mdAttributeDefaultLocale.getDescription(), attributeType.getDescription(), " (defaultLocale)");
mdAttributeDefaultLocale.apply();
metadata.addPair(mdAttributeDefaultLocale, cloneAttribute);
for (Locale locale : locales) {
MdAttributeCharacter mdAttributeLocale = new MdAttributeCharacter();
mdAttributeLocale.setValue(MdAttributeCharacterInfo.NAME, attributeType.getName() + locale.toString());
mdAttributeLocale.setValue(MdAttributeCharacterInfo.SIZE, "255");
mdAttributeLocale.setDefiningMdClass(mdBusiness);
LocalizedValueConverter.populate(mdAttributeLocale.getDisplayLabel(), attributeType.getLabel(), " (" + locale.toString() + ")");
LocalizedValueConverter.populate(mdAttributeLocale.getDescription(), attributeType.getDescription());
mdAttributeLocale.apply();
metadata.addPair(mdAttributeLocale, cloneAttribute);
}
// MdAttributeUUID mdAttributeOid = new MdAttributeUUID();
// mdAttributeOid.setValue(MdAttributeConcreteInfo.NAME,
// attributeType.getName() + "Oid");
// AbstractBuilder.populate(mdAttributeOid.getDisplayLabel(),
// attributeType.getLabel());
// AbstractBuilder.populate(mdAttributeOid.getDescription(),
// attributeType.getDescription());
// mdAttributeOid.setDefiningMdClass(mdBusiness);
// mdAttributeOid.apply();
} else if (attributeType instanceof AttributeLocalType) {
boolean isDisplayLabel = attributeType.getName().equals(DefaultAttribute.DISPLAY_LABEL.getName());
MdAttributeCharacter mdAttributeDefaultLocale = new MdAttributeCharacter();
mdAttributeDefaultLocale.setValue(MdAttributeCharacterInfo.NAME, attributeType.getName() + DEFAULT_LOCALE);
mdAttributeDefaultLocale.setValue(MdAttributeCharacterInfo.SIZE, "255");
mdAttributeDefaultLocale.setDefiningMdClass(mdBusiness);
LocalizedValueConverter.populate(mdAttributeDefaultLocale.getDisplayLabel(), isDisplayLabel ? type.getLabel() : attributeType.getLabel(), " (defaultLocale)");
LocalizedValueConverter.populate(mdAttributeDefaultLocale.getDescription(), attributeType.getDescription(), " (defaultLocale)");
mdAttributeDefaultLocale.apply();
for (Locale locale : locales) {
MdAttributeCharacter mdAttributeLocale = new MdAttributeCharacter();
mdAttributeLocale.setValue(MdAttributeCharacterInfo.NAME, attributeType.getName() + locale.toString());
mdAttributeLocale.setValue(MdAttributeCharacterInfo.SIZE, "255");
mdAttributeLocale.setDefiningMdClass(mdBusiness);
LocalizedValueConverter.populate(mdAttributeLocale.getDisplayLabel(), isDisplayLabel ? type.getLabel() : attributeType.getLabel(), " (" + locale.toString() + ")");
LocalizedValueConverter.populate(mdAttributeLocale.getDescription(), attributeType.getDescription());
mdAttributeLocale.apply();
}
}
}
use of com.runwaysdk.system.metadata.MdAttributeConcrete in project geoprism-registry by terraframe.
the class ServerGeoObjectType method createMdAttributeFromAttributeType.
public static MdAttributeConcrete createMdAttributeFromAttributeType(MdClass mdClass, AttributeType attributeType) {
MdAttributeConcrete mdAttribute = null;
if (attributeType.getType().equals(AttributeCharacterType.TYPE)) {
mdAttribute = new MdAttributeCharacter();
MdAttributeCharacter mdAttributeCharacter = (MdAttributeCharacter) mdAttribute;
mdAttributeCharacter.setDatabaseSize(MdAttributeCharacterInfo.MAX_CHARACTER_SIZE);
} else if (attributeType.getType().equals(AttributeDateType.TYPE)) {
mdAttribute = new MdAttributeDateTime();
} else if (attributeType.getType().equals(AttributeIntegerType.TYPE)) {
mdAttribute = new MdAttributeLong();
} else if (attributeType.getType().equals(AttributeFloatType.TYPE)) {
AttributeFloatType attributeFloatType = (AttributeFloatType) attributeType;
mdAttribute = new MdAttributeDouble();
mdAttribute.setValue(MdAttributeDoubleInfo.LENGTH, Integer.toString(attributeFloatType.getPrecision()));
mdAttribute.setValue(MdAttributeDoubleInfo.DECIMAL, Integer.toString(attributeFloatType.getScale()));
} else if (attributeType.getType().equals(AttributeTermType.TYPE)) {
mdAttribute = new MdAttributeTerm();
MdAttributeTerm mdAttributeTerm = (MdAttributeTerm) mdAttribute;
MdBusiness classifierMdBusiness = MdBusiness.getMdBusiness(Classifier.CLASS);
mdAttributeTerm.setMdBusiness(classifierMdBusiness);
// TODO implement support for multi-term
// mdAttribute = new MdAttributeMultiTerm();
// MdAttributeMultiTerm mdAttributeMultiTerm =
// (MdAttributeMultiTerm)mdAttribute;
//
// MdBusiness classifierMdBusiness =
// MdBusiness.getMdBusiness(Classifier.CLASS);
// mdAttributeMultiTerm.setMdBusiness(classifierMdBusiness);
} else if (attributeType.getType().equals(AttributeClassificationType.TYPE)) {
AttributeClassificationType attributeClassificationType = (AttributeClassificationType) attributeType;
String classificationTypeCode = attributeClassificationType.getClassificationType();
ClassificationType classificationType = ClassificationType.getByCode(classificationTypeCode);
mdAttribute = new MdAttributeClassification();
MdAttributeClassification mdAttributeTerm = (MdAttributeClassification) mdAttribute;
mdAttributeTerm.setReferenceMdClassification(classificationType.getMdClassificationObject());
Term root = attributeClassificationType.getRootTerm();
if (root != null) {
Classification classification = Classification.get(classificationType, root.getCode());
if (classification == null) {
net.geoprism.registry.DataNotFoundException ex = new net.geoprism.registry.DataNotFoundException();
ex.setTypeLabel(classificationType.getDisplayLabel().getValue());
ex.setDataIdentifier(root.getCode());
ex.setAttributeLabel(GeoObjectMetadata.get().getAttributeDisplayLabel(DefaultAttribute.CODE.getName()));
throw ex;
}
mdAttributeTerm.setValue(MdAttributeClassification.ROOT, classification.getOid());
}
} else if (attributeType.getType().equals(AttributeBooleanType.TYPE)) {
mdAttribute = new MdAttributeBoolean();
}
mdAttribute.setAttributeName(attributeType.getName());
mdAttribute.setValue(MdAttributeConcreteInfo.REQUIRED, Boolean.toString(attributeType.isRequired()));
if (attributeType.isUnique()) {
mdAttribute.addIndexType(MdAttributeIndices.UNIQUE_INDEX);
}
LocalizedValueConverter.populate(mdAttribute.getDisplayLabel(), attributeType.getLabel());
LocalizedValueConverter.populate(mdAttribute.getDescription(), attributeType.getDescription());
mdAttribute.setDefiningMdClass(mdClass);
mdAttribute.apply();
if (attributeType.getType().equals(AttributeTermType.TYPE)) {
MdAttributeTerm mdAttributeTerm = (MdAttributeTerm) mdAttribute;
// Build the parent class term root if it does not exist.
Classifier classTerm = TermConverter.buildIfNotExistdMdBusinessClassifier(mdClass);
// Create the root term node for this attribute
Classifier attributeTermRoot = TermConverter.buildIfNotExistAttribute(mdClass, mdAttributeTerm.getAttributeName(), classTerm);
// Make this the root term of the multi-attribute
attributeTermRoot.addClassifierTermAttributeRoots(mdAttributeTerm).apply();
AttributeTermType attributeTermType = (AttributeTermType) attributeType;
LocalizedValue label = LocalizedValueConverter.convert(attributeTermRoot.getDisplayLabel());
org.commongeoregistry.adapter.Term term = new org.commongeoregistry.adapter.Term(attributeTermRoot.getClassifierId(), label, new LocalizedValue(""));
attributeTermType.setRootTerm(term);
}
return mdAttribute;
}
use of com.runwaysdk.system.metadata.MdAttributeConcrete in project geoprism-registry by terraframe.
the class RegistryService method updateTerm.
/**
* Creates a new {@link Term} object and makes it a child of the term with the
* given code.
*
* @param sessionId
* @param parentTermCode
* TODO
* @param termJSON
* JSON of the term object.
* @return Updated {@link Term} object.
*/
@Request(RequestType.SESSION)
public Term updateTerm(String sessionId, String parentTermCode, String termJSON) {
JsonObject termJSONobj = JsonParser.parseString(termJSON).getAsJsonObject();
String termCode = termJSONobj.get(Term.JSON_CODE).getAsString();
LocalizedValue value = LocalizedValue.fromJSON(termJSONobj.get(Term.JSON_LOCALIZED_LABEL).getAsJsonObject());
Classifier classifier = TermConverter.updateClassifier(parentTermCode, termCode, value);
TermConverter termBuilder = new TermConverter(classifier.getKeyName());
Term returnTerm = termBuilder.build();
List<MdAttributeConcrete> mdAttrList = this.findRootClassifier(classifier);
this.refreshAttributeTermTypeInCache(mdAttrList);
return returnTerm;
}
use of com.runwaysdk.system.metadata.MdAttributeConcrete in project geoprism-registry by terraframe.
the class RegistryService method deleteTerm.
/**
* Deletes the {@link Term} with the given code. All children codoe will be
* deleted.
*
* @param sessionId
* @param parentTermCode
* TODO
* @param geoObjectTypeCode
* @param attributeTypeJSON
*/
@Request(RequestType.SESSION)
public void deleteTerm(String sessionId, String parentTermCode, String termCode) {
String parentClassifierKey = TermConverter.buildClassifierKeyFromTermCode(parentTermCode);
Classifier parent = Classifier.getByKey(parentClassifierKey);
TermConverter.enforceTermPermissions(parent, CGRPermissionAction.DELETE);
String classifierKey = Classifier.buildKey(parent.getKey(), termCode);
Classifier classifier = Classifier.getByKey(classifierKey);
List<MdAttributeConcrete> mdAttrList = this.findRootClassifier(classifier);
classifier.delete();
this.refreshAttributeTermTypeInCache(mdAttrList);
}
use of com.runwaysdk.system.metadata.MdAttributeConcrete in project geoprism-registry by terraframe.
the class MasterListVersion method createMdAttributeFromAttributeType.
protected static void createMdAttributeFromAttributeType(TableMetadata metadata, AttributeType attributeType, ServerGeoObjectType type, Collection<Locale> locales) {
MdBusiness mdBusiness = metadata.getMdBusiness();
if (!(attributeType instanceof AttributeTermType || attributeType instanceof AttributeClassificationType || attributeType instanceof AttributeLocalType)) {
MdAttributeConcrete mdAttribute = null;
if (attributeType.getType().equals(AttributeCharacterType.TYPE)) {
mdAttribute = new MdAttributeCharacter();
MdAttributeCharacter mdAttributeCharacter = (MdAttributeCharacter) mdAttribute;
mdAttributeCharacter.setDatabaseSize(MdAttributeCharacterInfo.MAX_CHARACTER_SIZE);
} else if (attributeType.getType().equals(AttributeDateType.TYPE)) {
mdAttribute = new MdAttributeDateTime();
} else if (attributeType.getType().equals(AttributeIntegerType.TYPE)) {
mdAttribute = new MdAttributeLong();
} else if (attributeType.getType().equals(AttributeFloatType.TYPE)) {
AttributeFloatType attributeFloatType = (AttributeFloatType) attributeType;
mdAttribute = new MdAttributeDouble();
mdAttribute.setValue(MdAttributeDoubleInfo.LENGTH, Integer.toString(attributeFloatType.getPrecision()));
mdAttribute.setValue(MdAttributeDoubleInfo.DECIMAL, Integer.toString(attributeFloatType.getScale()));
} else if (attributeType.getType().equals(AttributeBooleanType.TYPE)) {
mdAttribute = new MdAttributeBoolean();
} else {
throw new UnsupportedOperationException("Unsupported type [" + attributeType.getType() + "]");
}
mdAttribute.setAttributeName(attributeType.getName());
LocalizedValueConverter.populate(mdAttribute.getDisplayLabel(), attributeType.getLabel());
LocalizedValueConverter.populate(mdAttribute.getDescription(), attributeType.getDescription());
mdAttribute.setDefiningMdClass(mdBusiness);
mdAttribute.apply();
} else if (attributeType instanceof AttributeTermType || attributeType instanceof AttributeClassificationType) {
MdAttributeCharacter cloneAttribute = new MdAttributeCharacter();
cloneAttribute.setValue(MdAttributeConcreteInfo.NAME, attributeType.getName());
cloneAttribute.setValue(MdAttributeCharacterInfo.SIZE, "255");
cloneAttribute.addIndexType(MdAttributeIndices.NON_UNIQUE_INDEX);
LocalizedValueConverter.populate(cloneAttribute.getDisplayLabel(), attributeType.getLabel());
LocalizedValueConverter.populate(cloneAttribute.getDescription(), attributeType.getDescription());
cloneAttribute.setDefiningMdClass(mdBusiness);
cloneAttribute.apply();
metadata.addPair(cloneAttribute, cloneAttribute);
MdAttributeCharacter mdAttributeDefaultLocale = new MdAttributeCharacter();
mdAttributeDefaultLocale.setValue(MdAttributeCharacterInfo.NAME, attributeType.getName() + DEFAULT_LOCALE);
mdAttributeDefaultLocale.setValue(MdAttributeCharacterInfo.SIZE, "255");
mdAttributeDefaultLocale.setDefiningMdClass(mdBusiness);
LocalizedValueConverter.populate(mdAttributeDefaultLocale.getDisplayLabel(), attributeType.getLabel(), " (defaultLocale)");
LocalizedValueConverter.populate(mdAttributeDefaultLocale.getDescription(), attributeType.getDescription(), " (defaultLocale)");
mdAttributeDefaultLocale.apply();
metadata.addPair(mdAttributeDefaultLocale, cloneAttribute);
for (Locale locale : locales) {
MdAttributeCharacter mdAttributeLocale = new MdAttributeCharacter();
mdAttributeLocale.setValue(MdAttributeCharacterInfo.NAME, attributeType.getName() + locale.toString());
mdAttributeLocale.setValue(MdAttributeCharacterInfo.SIZE, "255");
mdAttributeLocale.setDefiningMdClass(mdBusiness);
LocalizedValueConverter.populate(mdAttributeLocale.getDisplayLabel(), attributeType.getLabel(), " (" + locale.toString() + ")");
LocalizedValueConverter.populate(mdAttributeLocale.getDescription(), attributeType.getDescription());
mdAttributeLocale.apply();
metadata.addPair(mdAttributeLocale, cloneAttribute);
}
// MdAttributeUUID mdAttributeOid = new MdAttributeUUID();
// mdAttributeOid.setValue(MdAttributeConcreteInfo.NAME,
// attributeType.getName() + "Oid");
// AbstractBuilder.populate(mdAttributeOid.getDisplayLabel(),
// attributeType.getLabel());
// AbstractBuilder.populate(mdAttributeOid.getDescription(),
// attributeType.getDescription());
// mdAttributeOid.setDefiningMdClass(mdBusiness);
// mdAttributeOid.apply();
} else if (attributeType instanceof AttributeLocalType) {
boolean isDisplayLabel = attributeType.getName().equals(DefaultAttribute.DISPLAY_LABEL.getName());
MdAttributeCharacter mdAttributeDefaultLocale = new MdAttributeCharacter();
mdAttributeDefaultLocale.setValue(MdAttributeCharacterInfo.NAME, attributeType.getName() + DEFAULT_LOCALE);
mdAttributeDefaultLocale.setValue(MdAttributeCharacterInfo.SIZE, "255");
mdAttributeDefaultLocale.setDefiningMdClass(mdBusiness);
LocalizedValueConverter.populate(mdAttributeDefaultLocale.getDisplayLabel(), isDisplayLabel ? type.getLabel() : attributeType.getLabel(), " (defaultLocale)");
LocalizedValueConverter.populate(mdAttributeDefaultLocale.getDescription(), attributeType.getDescription(), " (defaultLocale)");
mdAttributeDefaultLocale.apply();
for (Locale locale : locales) {
MdAttributeCharacter mdAttributeLocale = new MdAttributeCharacter();
mdAttributeLocale.setValue(MdAttributeCharacterInfo.NAME, attributeType.getName() + locale.toString());
mdAttributeLocale.setValue(MdAttributeCharacterInfo.SIZE, "255");
mdAttributeLocale.setDefiningMdClass(mdBusiness);
LocalizedValueConverter.populate(mdAttributeLocale.getDisplayLabel(), isDisplayLabel ? type.getLabel() : attributeType.getLabel(), " (" + locale.toString() + ")");
LocalizedValueConverter.populate(mdAttributeLocale.getDescription(), attributeType.getDescription());
mdAttributeLocale.apply();
}
}
}
Aggregations