Search in sources :

Example 1 with DataNotFoundException

use of com.runwaysdk.dataaccess.cache.DataNotFoundException in project geoprism-registry by terraframe.

the class BusinessType method deleteMdAttributeFromAttributeType.

/**
 * Delete the {@link MdAttributeConcreteDAOIF} from the given {
 *
 * @param type
 *          TODO
 * @param mdBusiness
 * @param attributeName
 */
@Transaction
public void deleteMdAttributeFromAttributeType(String attributeName) {
    MdAttributeConcreteDAOIF mdAttributeConcreteDAOIF = ServerGeoObjectType.getMdAttribute(this.getMdVertex(), attributeName);
    if (mdAttributeConcreteDAOIF != null) {
        if (mdAttributeConcreteDAOIF instanceof MdAttributeTermDAOIF || mdAttributeConcreteDAOIF instanceof MdAttributeMultiTermDAOIF) {
            String attributeTermKey = TermConverter.buildtAtttributeKey(this.getMdVertex().getTypeName(), mdAttributeConcreteDAOIF.definesAttribute());
            try {
                Classifier attributeTerm = Classifier.getByKey(attributeTermKey);
                attributeTerm.delete();
            } catch (DataNotFoundException e) {
            }
        }
        mdAttributeConcreteDAOIF.getBusinessDAO().delete();
    }
}
Also used : DataNotFoundException(com.runwaysdk.dataaccess.cache.DataNotFoundException) 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 2 with DataNotFoundException

use of com.runwaysdk.dataaccess.cache.DataNotFoundException in project geoprism-registry by terraframe.

the class MasterListVersion method getAttributesAsJson.

private JsonArray getAttributesAsJson() {
    Collection<Locale> locales = LocalizationFacade.getInstalledLocales();
    MasterList list = this.getMasterlist();
    Map<String, JsonArray> dependencies = new HashMap<String, JsonArray>();
    Map<String, String> baseAttributes = new HashMap<String, String>();
    List<String> attributesOrder = new LinkedList<String>();
    JsonArray hierarchies = list.getHierarchiesAsJson();
    for (int i = 0; i < hierarchies.size(); i++) {
        JsonObject hierarchy = hierarchies.get(i).getAsJsonObject();
        List<String> pCodes = list.getParentCodes(hierarchy);
        if (pCodes.size() > 0) {
            String hCode = hierarchy.get(DefaultAttribute.CODE.getName()).getAsString();
            String previous = null;
            for (String pCode : pCodes) {
                String attributeName = hCode.toLowerCase() + pCode.toLowerCase();
                baseAttributes.put(attributeName, attributeName);
                baseAttributes.put(attributeName + DEFAULT_LOCALE, attributeName);
                for (Locale locale : locales) {
                    baseAttributes.put(attributeName + locale.toString(), attributeName);
                }
                attributesOrder.add(attributeName);
                attributesOrder.add(attributeName + DEFAULT_LOCALE);
                for (Locale locale : locales) {
                    attributesOrder.add(attributeName + locale.toString());
                }
                if (previous != null) {
                    addDependency(dependencies, attributeName, previous);
                    addDependency(dependencies, attributeName + DEFAULT_LOCALE, previous);
                    for (Locale locale : locales) {
                        addDependency(dependencies, attributeName + locale.toString(), previous);
                    }
                }
                previous = attributeName;
            }
            if (previous != null) {
                addDependency(dependencies, DefaultAttribute.CODE.getName(), previous);
                addDependency(dependencies, DefaultAttribute.DISPLAY_LABEL.getName() + DEFAULT_LOCALE, previous);
                for (Locale locale : locales) {
                    addDependency(dependencies, DefaultAttribute.DISPLAY_LABEL.getName() + locale.toString(), previous);
                }
            }
        }
    }
    baseAttributes.put(DefaultAttribute.CODE.getName(), DefaultAttribute.CODE.getName());
    baseAttributes.put(DefaultAttribute.DISPLAY_LABEL.getName() + DEFAULT_LOCALE, DefaultAttribute.CODE.getName());
    for (Locale locale : locales) {
        baseAttributes.put(DefaultAttribute.DISPLAY_LABEL.getName() + locale.toString(), DefaultAttribute.CODE.getName());
    }
    attributesOrder.add(DefaultAttribute.CODE.getName());
    attributesOrder.add(DefaultAttribute.DISPLAY_LABEL.getName() + DEFAULT_LOCALE);
    for (Locale locale : locales) {
        attributesOrder.add(DefaultAttribute.DISPLAY_LABEL.getName() + locale.toString());
    }
    JsonArray attributes = new JsonArray();
    String mdBusinessId = this.getMdBusinessOid();
    if (mdBusinessId != null && mdBusinessId.length() > 0) {
        MdBusinessDAOIF mdBusiness = MdBusinessDAO.get(mdBusinessId);
        List<? extends MdAttributeConcreteDAOIF> mdAttributes = mdBusiness.definesAttributesOrdered();
        Collections.sort(mdAttributes, new ListTypeAttributeComparator(attributesOrder, mdAttributes));
        MdAttributeConcreteDAOIF mdGeometry = mdBusiness.definesAttribute(RegistryConstants.GEOMETRY_ATTRIBUTE_NAME);
        if (mdGeometry instanceof MdAttributePointDAOIF) {
            JsonObject longitude = new JsonObject();
            longitude.addProperty(NAME, "longitude");
            longitude.addProperty(LABEL, LocalizationFacade.localize(GeoObjectImportConfiguration.LONGITUDE_KEY));
            longitude.addProperty(TYPE, "none");
            attributes.add(longitude);
            JsonObject latitude = new JsonObject();
            latitude.addProperty(NAME, "latitude");
            latitude.addProperty(LABEL, LocalizationFacade.localize(GeoObjectImportConfiguration.LATITUDE_KEY));
            latitude.addProperty(TYPE, "none");
            attributes.add(latitude);
        }
        for (MdAttributeConcreteDAOIF mdAttribute : mdAttributes) {
            if (this.isValid(mdAttribute)) {
                String attributeName = mdAttribute.definesAttribute();
                try {
                    MasterListAttributeGroup group = MasterListAttributeGroup.getByKey(mdAttribute.getOid());
                    if (group != null) {
                        baseAttributes.put(mdAttribute.definesAttribute(), group.getSourceAttribute().getAttributeName());
                    }
                } catch (DataNotFoundException e) {
                // Ignore
                }
                JsonObject attribute = new JsonObject();
                attribute.addProperty(NAME, attributeName);
                attribute.addProperty(LABEL, mdAttribute.getDisplayLabel(Session.getCurrentLocale()));
                attribute.addProperty(TYPE, baseAttributes.containsKey(attributeName) ? "list" : "input");
                attribute.addProperty(BASE, baseAttributes.containsKey(attributeName) ? baseAttributes.get(attributeName) : attributeName);
                attribute.add(DEPENDENCY, dependencies.containsKey(attributeName) ? dependencies.get(attributeName) : new JsonArray());
                if (mdAttribute instanceof MdAttributeMomentDAOIF) {
                    attribute.addProperty(TYPE, "date");
                    attribute.add(VALUE, new JsonObject());
                }
                attributes.add(attribute);
            }
        }
    }
    return attributes;
}
Also used : Locale(java.util.Locale) DataNotFoundException(com.runwaysdk.dataaccess.cache.DataNotFoundException) MdBusinessDAOIF(com.runwaysdk.dataaccess.MdBusinessDAOIF) HashMap(java.util.HashMap) JsonObject(com.google.gson.JsonObject) MdAttributeMultiLineString(com.runwaysdk.system.gis.metadata.MdAttributeMultiLineString) MdAttributeLineString(com.runwaysdk.system.gis.metadata.MdAttributeLineString) MdAttributeMomentDAOIF(com.runwaysdk.dataaccess.MdAttributeMomentDAOIF) LinkedList(java.util.LinkedList) MdAttributePoint(com.runwaysdk.system.gis.metadata.MdAttributePoint) MdAttributeMultiPoint(com.runwaysdk.system.gis.metadata.MdAttributeMultiPoint) JsonArray(com.google.gson.JsonArray) MdAttributePointDAOIF(com.runwaysdk.gis.dataaccess.MdAttributePointDAOIF) ListTypeAttributeComparator(net.geoprism.registry.masterlist.ListTypeAttributeComparator) MdAttributeConcreteDAOIF(com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF)

Example 3 with DataNotFoundException

use of com.runwaysdk.dataaccess.cache.DataNotFoundException in project geoprism-registry by terraframe.

the class TermConverter method buildIfNotExistAttribute.

/**
 * Builds if not exists a {@link Classifier} object as a parent of terms of
 * the given {@link MdAttributeTerm} or a {@link MdAttributeMultiTerm}.
 *
 * @param mdClass
 *          {@link MdBusiness}
 * @param mdAttributeTermOrMultiName
 *          the name of the {@link MdAttributeTerm} or a
 *          {@link MdAttributeMultiTerm}
 * @param parent
 *
 * @return {@link Classifier} object as a parent of terms that pertain to the
 *         given {@link MdBusiness}.
 */
public static Classifier buildIfNotExistAttribute(MdClass mdClass, String mdAttributeTermOrMultiName, Classifier parent) {
    String attributeTermKey = buildtAtttributeKey(mdClass.getTypeName(), mdAttributeTermOrMultiName);
    Classifier attributeTerm = null;
    try {
        attributeTerm = Classifier.getByKey(attributeTermKey);
    } catch (DataNotFoundException e) {
        String classifierId = buildtAtttributeClassifierId(mdClass.getTypeName(), mdAttributeTermOrMultiName);
        attributeTerm = new Classifier();
        attributeTerm.setClassifierId(classifierId);
        attributeTerm.setClassifierPackage(RegistryConstants.REGISTRY_PACKAGE);
        // This will set the value of the display label to the locale of the user
        // performing the action.
        attributeTerm.getDisplayLabel().setValue(mdClass.getDisplayLabel().getValue());
        attributeTerm.getDisplayLabel().setDefaultValue(mdClass.getDisplayLabel().getDefaultValue());
        attributeTerm.apply();
        if (parent != null) {
            attributeTerm.addLink(parent, ClassifierIsARelationship.CLASS);
        }
    }
    return attributeTerm;
}
Also used : DataNotFoundException(com.runwaysdk.dataaccess.cache.DataNotFoundException) Classifier(net.geoprism.ontology.Classifier)

Example 4 with DataNotFoundException

use of com.runwaysdk.dataaccess.cache.DataNotFoundException 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 5 with DataNotFoundException

use of com.runwaysdk.dataaccess.cache.DataNotFoundException 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)

Aggregations

DataNotFoundException (com.runwaysdk.dataaccess.cache.DataNotFoundException)12 Request (com.runwaysdk.session.Request)5 MdAttributeConcreteDAOIF (com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF)4 Classifier (net.geoprism.ontology.Classifier)4 JsonObject (com.google.gson.JsonObject)3 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)3 JsonArray (com.google.gson.JsonArray)2 AttributeDoesNotExistException (com.runwaysdk.dataaccess.AttributeDoesNotExistException)2 MdAttributeMomentDAOIF (com.runwaysdk.dataaccess.MdAttributeMomentDAOIF)2 MdAttributeMultiTermDAOIF (com.runwaysdk.dataaccess.MdAttributeMultiTermDAOIF)2 MdAttributeTermDAOIF (com.runwaysdk.dataaccess.MdAttributeTermDAOIF)2 MdBusinessDAOIF (com.runwaysdk.dataaccess.MdBusinessDAOIF)2 MdAttributePointDAOIF (com.runwaysdk.gis.dataaccess.MdAttributePointDAOIF)2 Session (com.runwaysdk.session.Session)2 MdAttributeLineString (com.runwaysdk.system.gis.metadata.MdAttributeLineString)2 MdAttributeMultiLineString (com.runwaysdk.system.gis.metadata.MdAttributeMultiLineString)2 MdAttributeMultiPoint (com.runwaysdk.system.gis.metadata.MdAttributeMultiPoint)2 MdAttributePoint (com.runwaysdk.system.gis.metadata.MdAttributePoint)2 MdBusiness (com.runwaysdk.system.metadata.MdBusiness)2 HashMap (java.util.HashMap)2