Search in sources :

Example 1 with TermConverter

use of net.geoprism.registry.conversion.TermConverter in project geoprism-registry by terraframe.

the class RegistryService method updateTerm.

/**
 * Creates a new {@link Term} object and makes it a child of the term with the
 * given code.
 *
 * @param sessionId
 * @param parentTermCode
 *          TODO
 * @param termJSON
 *          JSON of the term object.
 * @return Updated {@link Term} object.
 */
@Request(RequestType.SESSION)
public Term updateTerm(String sessionId, String parentTermCode, String termJSON) {
    JsonObject termJSONobj = JsonParser.parseString(termJSON).getAsJsonObject();
    String termCode = termJSONobj.get(Term.JSON_CODE).getAsString();
    LocalizedValue value = LocalizedValue.fromJSON(termJSONobj.get(Term.JSON_LOCALIZED_LABEL).getAsJsonObject());
    Classifier classifier = TermConverter.updateClassifier(parentTermCode, termCode, value);
    TermConverter termBuilder = new TermConverter(classifier.getKeyName());
    Term returnTerm = termBuilder.build();
    List<MdAttributeConcrete> mdAttrList = this.findRootClassifier(classifier);
    this.refreshAttributeTermTypeInCache(mdAttrList);
    return returnTerm;
}
Also used : LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) JsonObject(com.google.gson.JsonObject) Classifier(net.geoprism.ontology.Classifier) MdAttributeMultiTerm(com.runwaysdk.system.metadata.MdAttributeMultiTerm) MdAttributeTerm(com.runwaysdk.system.metadata.MdAttributeTerm) Term(org.commongeoregistry.adapter.Term) MdAttributeConcrete(com.runwaysdk.system.metadata.MdAttributeConcrete) TermConverter(net.geoprism.registry.conversion.TermConverter) Request(com.runwaysdk.session.Request) OAuthClientRequest(org.apache.oltu.oauth2.client.request.OAuthClientRequest)

Example 2 with TermConverter

use of net.geoprism.registry.conversion.TermConverter 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 3 with TermConverter

use of net.geoprism.registry.conversion.TermConverter in project geoprism-registry by terraframe.

the class RegistryService method createTerm.

/**
 * Creates a new {@link Term} object and makes it a child of the term with the
 * given code.
 *
 * @param sessionId
 * @param parentTemCode
 *          The code of the parent [@link Term}.
 * @param termJSON
 *          JSON of the term object.
 *
 * @return Newly created {@link Term} object.
 */
@Request(RequestType.SESSION)
public Term createTerm(String sessionId, String parentTermCode, String termJSON) {
    JsonObject termJSONobj = JsonParser.parseString(termJSON).getAsJsonObject();
    LocalizedValue label = LocalizedValue.fromJSON(termJSONobj.get(Term.JSON_LOCALIZED_LABEL).getAsJsonObject());
    Term term = new Term(termJSONobj.get(Term.JSON_CODE).getAsString(), label, new LocalizedValue(""));
    Classifier classifier = TermConverter.createClassifierFromTerm(parentTermCode, term);
    TermConverter termBuilder = new TermConverter(classifier.getKeyName());
    Term returnTerm = termBuilder.build();
    List<MdAttributeConcrete> mdAttrList = this.findRootClassifier(classifier);
    this.refreshAttributeTermTypeInCache(mdAttrList);
    return returnTerm;
}
Also used : LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) JsonObject(com.google.gson.JsonObject) MdAttributeMultiTerm(com.runwaysdk.system.metadata.MdAttributeMultiTerm) MdAttributeTerm(com.runwaysdk.system.metadata.MdAttributeTerm) Term(org.commongeoregistry.adapter.Term) Classifier(net.geoprism.ontology.Classifier) MdAttributeConcrete(com.runwaysdk.system.metadata.MdAttributeConcrete) TermConverter(net.geoprism.registry.conversion.TermConverter) Request(com.runwaysdk.session.Request) OAuthClientRequest(org.apache.oltu.oauth2.client.request.OAuthClientRequest)

Example 4 with TermConverter

use of net.geoprism.registry.conversion.TermConverter in project geoprism-registry by terraframe.

the class XMLImporter method createTermOptions.

private void createTermOptions(Element attributeNode, Term root) {
    NodeList attributeList = attributeNode.getElementsByTagName("option");
    for (int i = 0; i < attributeList.getLength(); i++) {
        Node nNode = attributeList.item(i);
        if (nNode.getNodeType() == Node.ELEMENT_NODE) {
            Element elem = (Element) nNode;
            String code = elem.getAttribute("code");
            LocalizedValue label = this.getLabel(elem);
            LocalizedValue description = this.getDescription(elem);
            Term term = new Term(code, label, description);
            Classifier classifier = TermConverter.createClassifierFromTerm(root.getCode(), term);
            TermConverter termBuilder = new TermConverter(classifier.getKeyName());
            termBuilder.build();
        }
    }
}
Also used : LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ServerElement(net.geoprism.registry.model.ServerElement) Element(org.w3c.dom.Element) Term(org.commongeoregistry.adapter.Term) Classifier(net.geoprism.ontology.Classifier) TermConverter(net.geoprism.registry.conversion.TermConverter)

Aggregations

TermConverter (net.geoprism.registry.conversion.TermConverter)4 Term (org.commongeoregistry.adapter.Term)4 MdAttributeConcrete (com.runwaysdk.system.metadata.MdAttributeConcrete)3 MdAttributeTerm (com.runwaysdk.system.metadata.MdAttributeTerm)3 Classifier (net.geoprism.ontology.Classifier)3 LocalizedValue (org.commongeoregistry.adapter.dataaccess.LocalizedValue)3 JsonObject (com.google.gson.JsonObject)2 Request (com.runwaysdk.session.Request)2 MdAttributeMultiTerm (com.runwaysdk.system.metadata.MdAttributeMultiTerm)2 OAuthClientRequest (org.apache.oltu.oauth2.client.request.OAuthClientRequest)2 MdAttributeConcreteDAOIF (com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF)1 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)1 MdAttributeClassification (com.runwaysdk.system.metadata.MdAttributeClassification)1 ServerElement (net.geoprism.registry.model.ServerElement)1 AttributeClassificationType (org.commongeoregistry.adapter.metadata.AttributeClassificationType)1 AttributeFloatType (org.commongeoregistry.adapter.metadata.AttributeFloatType)1 AttributeTermType (org.commongeoregistry.adapter.metadata.AttributeTermType)1 Element (org.w3c.dom.Element)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1