use of com.runwaysdk.system.metadata.MdAttributeTerm 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.MdAttributeTerm in project geoprism-registry by terraframe.
the class TermConverter method enforceTermPermissions.
public static void enforceTermPermissions(Classifier parent, CGRPermissionActionIF action) {
GeoObjectTypePermissionServiceIF service = ServiceFactory.getGeoObjectTypePermissionService();
// Is this a root term for an {@link MdAttributeTerm}
try (OIterator<? extends MdAttributeTerm> attrTerm = parent.getAllClassifierTermAttributeRoots()) {
for (MdAttributeTerm mdAttributeTerm : attrTerm) {
MdClassDAOIF mdEntityDAOIF = MdClassDAO.get(mdAttributeTerm.getDefiningMdClassId());
ServerGeoObjectType geoObjectType = ServerGeoObjectType.get(mdEntityDAOIF.getTypeName(), true);
if (geoObjectType != null) {
Organization organization = geoObjectType.getOrganization();
service.enforceActorHasPermission(organization.getCode(), geoObjectType, geoObjectType.getIsPrivate(), action);
}
}
}
}
use of com.runwaysdk.system.metadata.MdAttributeTerm in project geoprism-registry by terraframe.
the class ServerGeoObjectType method updateMdAttributeFromAttributeType.
/**
* Creates an {@link MdAttributeConcrete} for the given {@link MdBusiness}
* from the given {@link AttributeType}
*
* @pre assumes no attribute has been defined on the type with the given name.
*
* @param mdBusiness
* Type to receive attribute definition
* @param attributeType
* newly defined attribute
*
* @return {@link AttributeType}
*/
@Transaction
public static MdAttributeConcrete updateMdAttributeFromAttributeType(MdClass mdClass, AttributeType attributeType) {
MdAttributeConcreteDAOIF mdAttributeConcreteDAOIF = getMdAttribute(mdClass, attributeType.getName());
if (mdAttributeConcreteDAOIF != null) {
// Get the type safe version
MdAttributeConcrete mdAttribute = (MdAttributeConcrete) BusinessFacade.get(mdAttributeConcreteDAOIF);
mdAttribute.lock();
try {
// The name cannot be updated
// mdAttribute.setAttributeName(attributeType.getName());
LocalizedValueConverter.populate(mdAttribute.getDisplayLabel(), attributeType.getLabel());
LocalizedValueConverter.populate(mdAttribute.getDescription(), attributeType.getDescription());
if (attributeType instanceof AttributeFloatType) {
// Refresh the terms
AttributeFloatType attributeFloatType = (AttributeFloatType) attributeType;
mdAttribute.setValue(MdAttributeDoubleInfo.LENGTH, Integer.toString(attributeFloatType.getPrecision()));
mdAttribute.setValue(MdAttributeDoubleInfo.DECIMAL, Integer.toString(attributeFloatType.getScale()));
} else if (attributeType instanceof AttributeClassificationType) {
MdAttributeClassification mdAttributeTerm = (MdAttributeClassification) mdAttribute;
AttributeClassificationType attributeClassificationType = (AttributeClassificationType) attributeType;
String classificationTypeCode = attributeClassificationType.getClassificationType();
ClassificationType classificationType = ClassificationType.getByCode(classificationTypeCode);
Term root = attributeClassificationType.getRootTerm();
if (root != null) {
Classification classification = Classification.get(classificationType, root.getCode());
mdAttributeTerm.setValue(MdAttributeClassification.ROOT, classification.getOid());
}
}
mdAttribute.apply();
} finally {
mdAttribute.unlock();
}
if (attributeType instanceof AttributeTermType) {
// Refresh the terms
AttributeTermType attributeTermType = (AttributeTermType) attributeType;
org.commongeoregistry.adapter.Term getRootTerm = attributeTermType.getRootTerm();
String classifierKey = TermConverter.buildClassifierKeyFromTermCode(getRootTerm.getCode());
TermConverter termBuilder = new TermConverter(classifierKey);
attributeTermType.setRootTerm(termBuilder.build());
}
return mdAttribute;
}
return null;
}
use of com.runwaysdk.system.metadata.MdAttributeTerm in project geoprism-registry by terraframe.
the class RegistryService method findRootClassifier.
private List<MdAttributeConcrete> findRootClassifier(Classifier classifier, List<MdAttributeConcrete> mdAttributeList) {
// Is this a root term for an {@link MdAttributeTerm}
OIterator<? extends MdAttributeTerm> attrTerm = classifier.getAllClassifierTermAttributeRoots();
for (MdAttributeTerm mdAttributeTerm : attrTerm) {
mdAttributeList.add(mdAttributeTerm);
}
OIterator<? extends MdAttributeMultiTerm> attrMultiTerm = classifier.getAllClassifierMultiTermAttributeRoots();
for (MdAttributeMultiTerm mdAttributeMultiTerm : attrMultiTerm) {
mdAttributeList.add(mdAttributeMultiTerm);
}
// Traverse up the tree
OIterator<? extends Classifier> parentTerms = classifier.getAllIsAParent();
for (Classifier parent : parentTerms) {
return this.findRootClassifier(parent, mdAttributeList);
}
return mdAttributeList;
}
Aggregations