Search in sources :

Example 6 with Classifier

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;
}
Also used : DataNotFoundException(com.runwaysdk.dataaccess.cache.DataNotFoundException) Classifier(net.geoprism.ontology.Classifier)

Example 7 with Classifier

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;
        }
    }
}
Also used : MdVertexDAOIF(com.runwaysdk.dataaccess.MdVertexDAOIF) TermValueException(net.geoprism.registry.io.TermValueException) BusinessType(net.geoprism.registry.BusinessType) MdAttributeTermDAOIF(com.runwaysdk.dataaccess.MdAttributeTermDAOIF) Classifier(net.geoprism.ontology.Classifier) Term(org.commongeoregistry.adapter.Term) AttributeTermType(org.commongeoregistry.adapter.metadata.AttributeTermType) TermReferenceProblem(net.geoprism.registry.etl.TermReferenceProblem) UnknownTermException(org.commongeoregistry.adapter.dataaccess.UnknownTermException)

Example 8 with Classifier

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;
        }
    }
}
Also used : MdBusinessDAOIF(com.runwaysdk.dataaccess.MdBusinessDAOIF) TermValueException(net.geoprism.registry.io.TermValueException) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) MdAttributeTermDAOIF(com.runwaysdk.dataaccess.MdAttributeTermDAOIF) Classifier(net.geoprism.ontology.Classifier) Term(org.commongeoregistry.adapter.Term) AttributeTermType(org.commongeoregistry.adapter.metadata.AttributeTermType) TermReferenceProblem(net.geoprism.registry.etl.TermReferenceProblem) UnknownTermException(org.commongeoregistry.adapter.dataaccess.UnknownTermException)

Example 9 with Classifier

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();
    }
}
Also used : DataNotFoundException(com.runwaysdk.dataaccess.cache.DataNotFoundException) MdAttributeDAOIF(com.runwaysdk.dataaccess.MdAttributeDAOIF) AttributeType(org.commongeoregistry.adapter.metadata.AttributeType) MdAttributeTermDAOIF(com.runwaysdk.dataaccess.MdAttributeTermDAOIF) Classifier(net.geoprism.ontology.Classifier) MdAttributeMultiTermDAOIF(com.runwaysdk.dataaccess.MdAttributeMultiTermDAOIF) MdAttributeConcreteDAOIF(com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 10 with Classifier

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;
}
Also used : DataNotFoundException(com.runwaysdk.dataaccess.cache.DataNotFoundException) MdAttributeDateTime(com.runwaysdk.system.metadata.MdAttributeDateTime) MdBusiness(com.runwaysdk.system.metadata.MdBusiness) Classifier(net.geoprism.ontology.Classifier) AttributeFloatType(org.commongeoregistry.adapter.metadata.AttributeFloatType) MdAttributeTerm(com.runwaysdk.system.metadata.MdAttributeTerm) LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) MdAttributeClassification(com.runwaysdk.system.metadata.MdAttributeClassification) MdAttributeConcrete(com.runwaysdk.system.metadata.MdAttributeConcrete) MdAttributeLong(com.runwaysdk.system.metadata.MdAttributeLong) MdAttributeClassification(com.runwaysdk.system.metadata.MdAttributeClassification) MdAttributeCharacter(com.runwaysdk.system.metadata.MdAttributeCharacter) Term(org.commongeoregistry.adapter.Term) MdAttributeTerm(com.runwaysdk.system.metadata.MdAttributeTerm) Term(org.commongeoregistry.adapter.Term) AttributeClassificationType(org.commongeoregistry.adapter.metadata.AttributeClassificationType) AttributeClassificationType(org.commongeoregistry.adapter.metadata.AttributeClassificationType) MdAttributeBoolean(com.runwaysdk.system.metadata.MdAttributeBoolean) MdAttributeDouble(com.runwaysdk.system.metadata.MdAttributeDouble) AttributeTermType(org.commongeoregistry.adapter.metadata.AttributeTermType)

Aggregations

Classifier (net.geoprism.ontology.Classifier)28 Term (org.commongeoregistry.adapter.Term)14 AttributeTermType (org.commongeoregistry.adapter.metadata.AttributeTermType)11 AttributeClassificationType (org.commongeoregistry.adapter.metadata.AttributeClassificationType)9 AttributeType (org.commongeoregistry.adapter.metadata.AttributeType)9 LocalizedValue (org.commongeoregistry.adapter.dataaccess.LocalizedValue)8 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)7 Classification (net.geoprism.registry.model.Classification)7 JsonObject (com.google.gson.JsonObject)6 VertexObject (com.runwaysdk.business.graph.VertexObject)5 DataNotFoundException (com.runwaysdk.dataaccess.cache.DataNotFoundException)5 MdAttributeTermDAOIF (com.runwaysdk.dataaccess.MdAttributeTermDAOIF)4 Request (com.runwaysdk.session.Request)4 MdAttributeConcrete (com.runwaysdk.system.metadata.MdAttributeConcrete)4 MdAttributeTerm (com.runwaysdk.system.metadata.MdAttributeTerm)4 TermValueException (net.geoprism.registry.io.TermValueException)4 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)4 VertexServerGeoObject (net.geoprism.registry.model.graph.VertexServerGeoObject)4 UnknownTermException (org.commongeoregistry.adapter.dataaccess.UnknownTermException)4 EdgeObject (com.runwaysdk.business.graph.EdgeObject)3