use of net.geoprism.ontology.Classifier in project geoprism-registry by terraframe.
the class TermConverter method buildIfNotExistdMdBusinessClassifier.
/**
* Builds if not exists a {@link Classifier} object as a parent of terms that
* pertain to the given {@link MdBusiness}.
*
* @param mdClass
* {@link MdBusiness}
*
* @return {@link Classifier} object as a parent of terms that pertain to the
* given {@link MdBusiness}.
*/
public static Classifier buildIfNotExistdMdBusinessClassifier(MdClass mdClass) {
String classTermKey = buildRootClassKey(mdClass.getTypeName());
Classifier classTerm = null;
try {
classTerm = Classifier.getByKey(classTermKey);
} catch (DataNotFoundException e) {
String classifierId = buildRootClassClassifierId(mdClass.getTypeName());
classTerm = new Classifier();
classTerm.setClassifierId(classifierId);
classTerm.setClassifierPackage(RegistryConstants.REGISTRY_PACKAGE);
// This will set the value of the display label to the locale of the user
// performing the action.
classTerm.getDisplayLabel().setValue(mdClass.getDisplayLabel().getValue());
classTerm.getDisplayLabel().setDefaultValue(mdClass.getDisplayLabel().getDefaultValue());
classTerm.apply();
Classifier rootClassTerm = Classifier.getByKey(RegistryConstants.TERM_CLASS);
classTerm.addLink(rootClassTerm, ClassifierIsARelationship.CLASS);
}
return classTerm;
}
use of net.geoprism.ontology.Classifier in project geoprism-registry by terraframe.
the class BusinessObjectImporter method setTermValue.
protected void setTermValue(BusinessObject entity, AttributeType attributeType, String attributeName, Object value) {
if (!this.configuration.isExclusion(attributeName, value.toString())) {
try {
BusinessType type = this.configuration.getType();
MdVertexDAOIF mdBusiness = type.getMdVertexDAO();
MdAttributeTermDAOIF mdAttribute = (MdAttributeTermDAOIF) mdBusiness.definesAttribute(attributeName);
Classifier classifier = Classifier.findMatchingTerm(value.toString().trim(), mdAttribute);
if (classifier == null) {
Term rootTerm = ((AttributeTermType) attributeType).getRootTerm();
TermReferenceProblem trp = new TermReferenceProblem(value.toString(), rootTerm.getCode(), mdAttribute.getOid(), attributeName, attributeType.getLabel().getValue());
trp.addAffectedRowNumber(this.progressListener.getWorkProgress() + 1);
trp.setHistoryId(this.configuration.getHistoryId());
this.progressListener.addReferenceProblem(trp);
} else {
entity.setValue(attributeName, classifier.getOid());
}
} catch (UnknownTermException e) {
TermValueException ex = new TermValueException();
ex.setAttributeLabel(e.getAttribute().getLabel().getValue());
ex.setCode(e.getCode());
throw e;
}
}
}
use of net.geoprism.ontology.Classifier in project geoprism-registry by terraframe.
the class GeoObjectImporter method setTermValue.
protected void setTermValue(ServerGeoObjectIF entity, AttributeType attributeType, String attributeName, Object value, Date startDate, Date endDate) {
if (!this.configuration.isExclusion(attributeName, value.toString())) {
try {
ServerGeoObjectType type = this.configuration.getType();
MdBusinessDAOIF mdBusiness = type.getMdBusinessDAO();
MdAttributeTermDAOIF mdAttribute = (MdAttributeTermDAOIF) mdBusiness.definesAttribute(attributeName);
if (mdAttribute == null && type.getSuperType() != null) {
mdAttribute = (MdAttributeTermDAOIF) type.getSuperType().getMdBusinessDAO().definesAttribute(attributeName);
}
Classifier classifier = Classifier.findMatchingTerm(value.toString().trim(), mdAttribute);
if (classifier == null) {
Term rootTerm = ((AttributeTermType) attributeType).getRootTerm();
TermReferenceProblem trp = new TermReferenceProblem(value.toString(), rootTerm.getCode(), mdAttribute.getOid(), attributeName, attributeType.getLabel().getValue());
trp.addAffectedRowNumber(this.progressListener.getWorkProgress() + 1);
trp.setHistoryId(this.configuration.getHistoryId());
this.progressListener.addReferenceProblem(trp);
} else {
entity.setValue(attributeName, classifier.getOid(), startDate, endDate);
}
} catch (UnknownTermException e) {
TermValueException ex = new TermValueException();
ex.setAttributeLabel(e.getAttribute().getLabel().getValue());
ex.setCode(e.getCode());
throw e;
}
}
}
use of net.geoprism.ontology.Classifier in project geoprism-registry by terraframe.
the class ServerGeoObjectType method deleteMdAttributeFromAttributeType.
/**
* Delete the {@link MdAttributeConcreteDAOIF} from the given {
*
* @param type
* TODO
* @param mdBusiness
* @param attributeName
*/
@Transaction
public void deleteMdAttributeFromAttributeType(String attributeName) {
MdAttributeConcreteDAOIF mdAttributeConcreteDAOIF = getMdAttribute(this.mdBusiness, attributeName);
if (mdAttributeConcreteDAOIF != null) {
if (mdAttributeConcreteDAOIF instanceof MdAttributeTermDAOIF || mdAttributeConcreteDAOIF instanceof MdAttributeMultiTermDAOIF) {
String attributeTermKey = TermConverter.buildtAtttributeKey(this.mdBusiness.getTypeName(), mdAttributeConcreteDAOIF.definesAttribute());
try {
Classifier attributeTerm = Classifier.getByKey(attributeTermKey);
attributeTerm.delete();
} catch (DataNotFoundException e) {
}
}
mdAttributeConcreteDAOIF.getBusinessDAO().delete();
Optional<AttributeType> optional = this.type.getAttribute(attributeName);
if (optional.isPresent()) {
ListType.deleteMdAttribute(this.universal, optional.get());
}
}
MdAttributeDAOIF mdAttributeDAO = this.mdVertex.definesAttribute(attributeName);
if (mdAttributeDAO != null) {
mdAttributeDAO.getBusinessDAO().delete();
}
}
use of net.geoprism.ontology.Classifier 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;
}
Aggregations