use of net.geoprism.ontology.Classifier 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();
}
}
use of net.geoprism.ontology.Classifier in project geoprism-registry by terraframe.
the class ListTypeVersion method publish.
private void publish(ListType listType, ServerGeoObjectType type, ServerGeoObjectIF go, Business business, Collection<AttributeType> attributes, Map<ServerHierarchyType, List<ServerGeoObjectType>> ancestorMap, Set<ServerHierarchyType> hierarchiesOfSubTypes, Collection<Locale> locales) {
VertexServerGeoObject vertexGo = (VertexServerGeoObject) go;
business.setValue(RegistryConstants.GEOMETRY_ATTRIBUTE_NAME, go.getGeometry());
for (AttributeType attribute : attributes) {
String name = attribute.getName();
business.setValue(ORIGINAL_OID, go.getRunwayId());
if (this.isValid(attribute)) {
Object value = go.getValue(name, this.getForDate());
if (value != null) {
if (value instanceof LocalizedValue && ((LocalizedValue) value).isNull()) {
continue;
}
if (attribute instanceof AttributeTermType) {
Classifier classifier = (Classifier) value;
Term term = ((AttributeTermType) attribute).getTermByCode(classifier.getClassifierId()).get();
LocalizedValue label = term.getLabel();
this.setValue(business, name, term.getCode());
this.setValue(business, name + DEFAULT_LOCALE, label.getValue(LocalizedValue.DEFAULT_LOCALE));
for (Locale locale : locales) {
this.setValue(business, name + locale.toString(), label.getValue(locale));
}
} else if (attribute instanceof AttributeClassificationType) {
String classificationTypeCode = ((AttributeClassificationType) attribute).getClassificationType();
ClassificationType classificationType = ClassificationType.getByCode(classificationTypeCode);
Classification classification = Classification.getByOid(classificationType, (String) value);
LocalizedValue label = classification.getDisplayLabel();
this.setValue(business, name, classification.getCode());
this.setValue(business, name + DEFAULT_LOCALE, label.getValue(LocalizedValue.DEFAULT_LOCALE));
for (Locale locale : locales) {
this.setValue(business, name + locale.toString(), label.getValue(locale));
}
} else if (attribute instanceof AttributeLocalType) {
LocalizedValue label = (LocalizedValue) value;
String defaultLocale = label.getValue(LocalizedValue.DEFAULT_LOCALE);
if (defaultLocale == null) {
defaultLocale = "";
}
this.setValue(business, name + DEFAULT_LOCALE, defaultLocale);
for (Locale locale : locales) {
String localeValue = label.getValue(locale);
if (localeValue == null) {
localeValue = "";
}
this.setValue(business, name + locale.toString(), localeValue);
}
} else {
this.setValue(business, name, value);
}
}
}
}
Set<Entry<ServerHierarchyType, List<ServerGeoObjectType>>> entries = ancestorMap.entrySet();
for (Entry<ServerHierarchyType, List<ServerGeoObjectType>> entry : entries) {
ServerHierarchyType hierarchy = entry.getKey();
Map<String, LocationInfo> map = vertexGo.getAncestorMap(hierarchy, entry.getValue());
Set<Entry<String, LocationInfo>> locations = map.entrySet();
for (Entry<String, LocationInfo> location : locations) {
String pCode = location.getKey();
LocationInfo vObject = location.getValue();
if (vObject != null) {
String attributeName = hierarchy.getCode().toLowerCase() + pCode.toLowerCase();
this.setValue(business, attributeName, vObject.getCode());
this.setValue(business, attributeName + DEFAULT_LOCALE, vObject.getLabel());
for (Locale locale : locales) {
this.setValue(business, attributeName + locale.toString(), vObject.getLabel(locale));
}
}
}
}
for (ServerHierarchyType hierarchy : hierarchiesOfSubTypes) {
ServerParentTreeNode node = go.getParentsForHierarchy(hierarchy, false, this.getForDate());
List<ServerParentTreeNode> parents = node.getParents();
if (parents.size() > 0) {
ServerParentTreeNode parent = parents.get(0);
String attributeName = hierarchy.getCode().toLowerCase();
ServerGeoObjectIF geoObject = parent.getGeoObject();
LocalizedValue label = geoObject.getDisplayLabel();
this.setValue(business, attributeName, geoObject.getCode());
this.setValue(business, attributeName + DEFAULT_LOCALE, label.getValue(DEFAULT_LOCALE));
for (Locale locale : locales) {
this.setValue(business, attributeName + locale.toString(), label.getValue(locale));
}
}
}
if (type.getGeometryType().equals(GeometryType.MULTIPOINT) || type.getGeometryType().equals(GeometryType.POINT) && listType.getIncludeLatLong()) {
Geometry geom = vertexGo.getGeometry();
if (geom instanceof MultiPoint) {
MultiPoint mp = (MultiPoint) geom;
Coordinate[] coords = mp.getCoordinates();
Coordinate firstCoord = coords[0];
this.setValue(business, "latitude", String.valueOf(firstCoord.y));
this.setValue(business, "longitude", String.valueOf(firstCoord.x));
} else if (geom instanceof Point) {
Point point = (Point) geom;
Coordinate firstCoord = point.getCoordinate();
this.setValue(business, "latitude", String.valueOf(firstCoord.y));
this.setValue(business, "longitude", String.valueOf(firstCoord.x));
}
}
business.apply();
}
use of net.geoprism.ontology.Classifier in project geoprism-registry by terraframe.
the class MasterListVersion method publish.
private void publish(ServerGeoObjectIF go, Business business, Collection<AttributeType> attributes, Map<ServerHierarchyType, List<ServerGeoObjectType>> ancestorMap, Set<ServerHierarchyType> hierarchiesOfSubTypes, Collection<Locale> locales) {
VertexServerGeoObject vertexGo = (VertexServerGeoObject) go;
boolean hasData = false;
business.setValue(RegistryConstants.GEOMETRY_ATTRIBUTE_NAME, go.getGeometry());
for (AttributeType attribute : attributes) {
String name = attribute.getName();
business.setValue(ORIGINAL_OID, go.getRunwayId());
if (this.isValid(attribute)) {
Object value = go.getValue(name, this.getForDate());
if (value != null) {
if (value instanceof LocalizedValue && ((LocalizedValue) value).isNull()) {
continue;
}
if (!name.equals(DefaultAttribute.CODE.getName()) && !name.equals(DefaultAttribute.INVALID.getName()) && attribute.isChangeOverTime() && (!name.equals(DefaultAttribute.EXISTS.getName()) || (value instanceof Boolean && ((Boolean) value)))) {
hasData = true;
}
if (attribute instanceof AttributeTermType) {
Classifier classifier = (Classifier) value;
Term term = ((AttributeTermType) attribute).getTermByCode(classifier.getClassifierId()).get();
LocalizedValue label = term.getLabel();
this.setValue(business, name, term.getCode());
this.setValue(business, name + DEFAULT_LOCALE, label.getValue(LocalizedValue.DEFAULT_LOCALE));
for (Locale locale : locales) {
this.setValue(business, name + locale.toString(), label.getValue(locale));
}
} else if (attribute instanceof AttributeClassificationType) {
String classificationType = ((AttributeClassificationType) attribute).getClassificationType();
MdClassificationDAOIF mdClassificationDAO = MdClassificationDAO.getMdClassificationDAO(classificationType);
MdVertexDAOIF mdVertexDAO = mdClassificationDAO.getReferenceMdVertexDAO();
VertexObject classification = VertexObject.get(mdVertexDAO, (String) value);
LocalizedValue label = LocalizedValueConverter.convert(classification.getEmbeddedComponent(AbstractClassification.DISPLAYLABEL));
this.setValue(business, name, classification.getObjectValue(AbstractClassification.CODE));
this.setValue(business, name + DEFAULT_LOCALE, label.getValue(LocalizedValue.DEFAULT_LOCALE));
for (Locale locale : locales) {
this.setValue(business, name + locale.toString(), label.getValue(locale));
}
} else if (attribute instanceof AttributeLocalType) {
LocalizedValue label = (LocalizedValue) value;
String defaultLocale = label.getValue(LocalizedValue.DEFAULT_LOCALE);
if (defaultLocale == null) {
defaultLocale = "";
}
this.setValue(business, name + DEFAULT_LOCALE, defaultLocale);
for (Locale locale : locales) {
String localeValue = label.getValue(locale);
if (localeValue == null) {
localeValue = "";
}
this.setValue(business, name + locale.toString(), localeValue);
}
} else {
this.setValue(business, name, value);
}
}
}
}
if (hasData) {
Set<Entry<ServerHierarchyType, List<ServerGeoObjectType>>> entries = ancestorMap.entrySet();
for (Entry<ServerHierarchyType, List<ServerGeoObjectType>> entry : entries) {
ServerHierarchyType hierarchy = entry.getKey();
Map<String, LocationInfo> map = vertexGo.getAncestorMap(hierarchy, entry.getValue());
Set<Entry<String, LocationInfo>> locations = map.entrySet();
for (Entry<String, LocationInfo> location : locations) {
String pCode = location.getKey();
LocationInfo vObject = location.getValue();
if (vObject != null) {
String attributeName = hierarchy.getCode().toLowerCase() + pCode.toLowerCase();
this.setValue(business, attributeName, vObject.getCode());
this.setValue(business, attributeName + DEFAULT_LOCALE, vObject.getLabel());
for (Locale locale : locales) {
this.setValue(business, attributeName + locale.toString(), vObject.getLabel(locale));
}
}
}
}
for (ServerHierarchyType hierarchy : hierarchiesOfSubTypes) {
ServerParentTreeNode node = go.getParentsForHierarchy(hierarchy, false, this.getForDate());
List<ServerParentTreeNode> parents = node.getParents();
if (parents.size() > 0) {
ServerParentTreeNode parent = parents.get(0);
String attributeName = hierarchy.getCode().toLowerCase();
ServerGeoObjectIF geoObject = parent.getGeoObject();
LocalizedValue label = geoObject.getDisplayLabel();
this.setValue(business, attributeName, geoObject.getCode());
this.setValue(business, attributeName + DEFAULT_LOCALE, label.getValue(DEFAULT_LOCALE));
for (Locale locale : locales) {
this.setValue(business, attributeName + locale.toString(), label.getValue(locale));
}
}
}
business.apply();
}
}
use of net.geoprism.ontology.Classifier 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;
}
use of net.geoprism.ontology.Classifier in project geoprism-registry by terraframe.
the class TermConverter method createClassifierFromTerm.
@Transaction
public static Classifier createClassifierFromTerm(String parentTermCode, Term term) {
String parentClassifierKey = buildClassifierKeyFromTermCode(parentTermCode);
Classifier parent = Classifier.getByKey(parentClassifierKey);
enforceTermPermissions(parent, CGRPermissionAction.CREATE);
Classifier classifier = new Classifier();
classifier.setClassifierId(term.getCode());
classifier.setClassifierPackage(parent.getKey());
// This will set the value of the display label to the locale of the user
// performing the action.
LocalizedValueConverter.populate(classifier.getDisplayLabel(), term.getLabel());
classifier.apply();
classifier.addLink(parent, ClassifierIsARelationship.CLASS);
return classifier;
}
Aggregations