Search in sources :

Example 1 with MdAttributeTerm

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;
}
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)

Example 2 with MdAttributeTerm

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);
            }
        }
    }
}
Also used : MdAttributeTerm(com.runwaysdk.system.metadata.MdAttributeTerm) Organization(net.geoprism.registry.Organization) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) MdClassDAOIF(com.runwaysdk.dataaccess.MdClassDAOIF) GeoObjectTypePermissionServiceIF(net.geoprism.registry.permission.GeoObjectTypePermissionServiceIF)

Example 3 with MdAttributeTerm

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;
}
Also used : MdAttributeClassification(com.runwaysdk.system.metadata.MdAttributeClassification) 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) AttributeFloatType(org.commongeoregistry.adapter.metadata.AttributeFloatType) MdAttributeClassification(com.runwaysdk.system.metadata.MdAttributeClassification) MdAttributeConcrete(com.runwaysdk.system.metadata.MdAttributeConcrete) AttributeTermType(org.commongeoregistry.adapter.metadata.AttributeTermType) TermConverter(net.geoprism.registry.conversion.TermConverter) MdAttributeConcreteDAOIF(com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 4 with MdAttributeTerm

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;
}
Also used : MdAttributeTerm(com.runwaysdk.system.metadata.MdAttributeTerm) MdAttributeMultiTerm(com.runwaysdk.system.metadata.MdAttributeMultiTerm) Classifier(net.geoprism.ontology.Classifier)

Aggregations

MdAttributeTerm (com.runwaysdk.system.metadata.MdAttributeTerm)4 MdAttributeClassification (com.runwaysdk.system.metadata.MdAttributeClassification)2 MdAttributeConcrete (com.runwaysdk.system.metadata.MdAttributeConcrete)2 Classifier (net.geoprism.ontology.Classifier)2 Term (org.commongeoregistry.adapter.Term)2 AttributeClassificationType (org.commongeoregistry.adapter.metadata.AttributeClassificationType)2 AttributeFloatType (org.commongeoregistry.adapter.metadata.AttributeFloatType)2 AttributeTermType (org.commongeoregistry.adapter.metadata.AttributeTermType)2 MdAttributeConcreteDAOIF (com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF)1 MdClassDAOIF (com.runwaysdk.dataaccess.MdClassDAOIF)1 DataNotFoundException (com.runwaysdk.dataaccess.cache.DataNotFoundException)1 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)1 MdAttributeBoolean (com.runwaysdk.system.metadata.MdAttributeBoolean)1 MdAttributeCharacter (com.runwaysdk.system.metadata.MdAttributeCharacter)1 MdAttributeDateTime (com.runwaysdk.system.metadata.MdAttributeDateTime)1 MdAttributeDouble (com.runwaysdk.system.metadata.MdAttributeDouble)1 MdAttributeLong (com.runwaysdk.system.metadata.MdAttributeLong)1 MdAttributeMultiTerm (com.runwaysdk.system.metadata.MdAttributeMultiTerm)1 MdBusiness (com.runwaysdk.system.metadata.MdBusiness)1 Organization (net.geoprism.registry.Organization)1