use of net.geoprism.ontology.Classifier in project geoprism-registry by terraframe.
the class ChangeRequestServiceTest method testUpdateGeoObjectTermCR_Verify.
@Request
private void testUpdateGeoObjectTermCR_Verify(String[] data) throws Exception {
final String attrName = FastTestDataset.AT_RELIGION.getAttributeName();
final String oldOid = data[1];
final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
sdf.setTimeZone(GeoRegistryUtil.SYSTEM_TIMEZONE);
final Date newStartDate = sdf.parse(NEW_START_DATE);
final Date newEndDate = sdf.parse(NEW_END_DATE);
ChangeRequestQuery crq = new ChangeRequestQuery(new QueryFactory());
Assert.assertEquals(1, crq.getCount());
ChangeRequest cr = crq.getIterator().next();
Assert.assertEquals(AllGovernanceStatus.ACCEPTED.name(), cr.getGovernanceStatus().name());
AbstractAction action = cr.getAllAction().next();
Assert.assertTrue(action instanceof UpdateAttributeAction);
Assert.assertEquals(FastTestDataset.CAMBODIA.getCode(), cr.getGeoObjectCode());
Assert.assertEquals(FastTestDataset.CAMBODIA.getGeoObjectType().getCode(), cr.getGeoObjectTypeCode());
Assert.assertEquals(FastTestDataset.ORG_CGOV.getCode(), cr.getOrganizationCode());
VertexServerGeoObject cambodia = (VertexServerGeoObject) FastTestDataset.CAMBODIA.getServerObject();
ValueOverTimeCollection votc = cambodia.getValuesOverTime(attrName);
Assert.assertEquals(1, votc.size());
ValueOverTime vot1 = votc.get(0);
Assert.assertNotNull(vot1.getOid());
Assert.assertEquals(oldOid, vot1.getOid());
Assert.assertEquals(newStartDate, vot1.getStartDate());
Assert.assertEquals(newEndDate, vot1.getEndDate());
String classyId = ((Classifier) cambodia.getValue(attrName, newStartDate)).getOid();
Assert.assertEquals(FastTestDataset.T_Islam.fetchClassifier().getOid(), classyId);
Assert.assertEquals(classyId, vot1.getValue());
}
use of net.geoprism.ontology.Classifier in project geoprism-registry by terraframe.
the class ListType method getRestriction.
public BasicVertexRestriction getRestriction(ServerGeoObjectType type, Date forDate) {
String filterJson = this.getFilterJson();
if (filterJson != null && filterJson.length() > 0) {
JsonArray filters = JsonParser.parseString(filterJson).getAsJsonArray();
CompositeRestriction restriction = new CompositeRestriction();
for (int i = 0; i < filters.size(); i++) {
JsonObject filter = filters.get(i).getAsJsonObject();
String attributeName = filter.get("attribute").getAsString();
String operation = filter.get("operation").getAsString();
AttributeType attributeType = type.getAttribute(attributeName).get();
MdAttributeDAOIF mdAttribute = type.getMdVertex().definesAttribute(attributeName);
if (attributeType instanceof AttributeDateType) {
String value = filter.get("value").getAsString();
Date date = GeoRegistryUtil.parseDate(value, false);
restriction.add(new AttributeValueRestriction(mdAttribute, operation, date, forDate));
} else if (attributeType instanceof AttributeBooleanType) {
String value = filter.get("value").getAsString();
Boolean bVal = Boolean.valueOf(value);
restriction.add(new AttributeValueRestriction(mdAttribute, operation, bVal, forDate));
} else if (attributeType instanceof AttributeTermType) {
String code = filter.get("value").getAsString();
Term root = ((AttributeTermType) attributeType).getRootTerm();
String parent = TermConverter.buildClassifierKeyFromTermCode(root.getCode());
String classifierKey = Classifier.buildKey(parent, code);
Classifier classifier = Classifier.getByKey(classifierKey);
restriction.add(new AttributeValueRestriction(mdAttribute, operation, classifier.getOid(), forDate));
} else if (attributeType instanceof AttributeClassificationType) {
JsonObject object = filter.get("value").getAsJsonObject();
Term term = Term.fromJSON(object);
MdClassificationDAOIF mdClassification = ((MdAttributeClassificationDAOIF) mdAttribute).getMdClassificationDAOIF();
MdEdgeDAOIF mdEdge = mdClassification.getReferenceMdEdgeDAO();
ClassificationType classificationType = new ClassificationType(mdClassification);
Classification classification = Classification.get(classificationType, term.getCode());
restriction.add(new AttributeValueRestriction(mdAttribute, operation, classification.getVertex().getRID(), forDate));
} else {
String value = filter.get("value").getAsString();
restriction.add(new AttributeValueRestriction(mdAttribute, operation, value, forDate));
}
}
if (restriction.getRestrictions().size() > 0) {
return restriction;
}
}
return null;
}
use of net.geoprism.ontology.Classifier in project geoprism-registry by terraframe.
the class PatchTerms method doIt.
@Transaction
private void doIt() {
ClassifierQuery gQuery = new ClassifierQuery(new QueryFactory());
Classifier clazz = this.getByClassifierId("CLASS");
BusinessDAO clazzDAO = BusinessDAO.get(clazz.getOid()).getBusinessDAO();
clazzDAO.setValue(Classifier.CLASSIFIERPACKAGE, RegistryConstants.REGISTRY_PACKAGE);
clazzDAO.setValue(Classifier.KEYNAME, "CLASS");
clazzDAO.apply();
Classifier root = this.getByClassifierId("ROOT");
BusinessDAO rootDAO = BusinessDAO.get(root.getOid()).getBusinessDAO();
rootDAO.setValue(Classifier.CLASSIFIERPACKAGE, "ROOT");
rootDAO.setValue(Classifier.KEYNAME, "ROOT");
rootDAO.apply();
try (OIterator<? extends Classifier> it = gQuery.getIterator()) {
while (it.hasNext()) {
Classifier classifier = it.next();
LinkedList<Term> parents = new LinkedList<>(GeoEntityUtil.getOrderedAncestors(root, classifier, ClassifierIsARelationship.CLASS));
Collections.reverse(parents);
// Root -> Class Root -> Class -> Attribute -> Option
if (parents.size() == 4) {
Iterator<Term> pit = parents.iterator();
// while (pit.hasNext())
// {
// Classifier p = (Classifier) pit.next();
//
// // logger.error("[" + p.getClassifierId() + "]: ");
// System.out.println(" Parent [" + p.getClassifierId() + "]: ");
// }
pit = parents.iterator();
pit.next();
Classifier parent = (Classifier) pit.next();
classifier.appLock();
classifier.setClassifierPackage(parent.getKey());
classifier.setKeyName(Classifier.buildKey(parent.getKey(), classifier.getClassifierId()));
classifier.apply();
} else if (!(classifier.getOid().equals(clazz.getOid()) || classifier.getOid().equals(root.getOid()))) {
classifier.appLock();
classifier.setClassifierPackage(RegistryConstants.REGISTRY_PACKAGE);
classifier.setKeyName(Classifier.buildKey(RegistryConstants.REGISTRY_PACKAGE, classifier.getClassifierId()));
classifier.apply();
}
}
}
}
use of net.geoprism.ontology.Classifier in project geoprism-registry by terraframe.
the class TermConverter method updateClassifier.
@Transaction
public static Classifier updateClassifier(String parentTermCode, String termCode, LocalizedValue value) {
String parentClassifierKey = buildClassifierKeyFromTermCode(parentTermCode);
Classifier parent = Classifier.getByKey(parentClassifierKey);
enforceTermPermissions(parent, CGRPermissionAction.WRITE);
String classifierKey = Classifier.buildKey(parent.getKey(), termCode);
Classifier classifier = Classifier.getByKey(classifierKey);
classifier.lock();
classifier.setClassifierId(termCode);
LocalizedValueConverter.populate(classifier.getDisplayLabel(), value);
classifier.apply();
return classifier;
}
use of net.geoprism.ontology.Classifier in project geoprism-registry by terraframe.
the class GeoObjectUtil method convertToTermString.
@SuppressWarnings("unchecked")
public static String convertToTermString(AttributeTermType attributeType, Object value) {
StringBuilder builder = new StringBuilder();
boolean first = true;
if (value instanceof Classifier) {
if (!first) {
builder.append(",");
}
builder.append(((Classifier) value).getDisplayLabel().getValue());
first = false;
} else {
Iterator<String> codes = (Iterator<String>) value;
if (codes != null) {
while (codes.hasNext()) {
String code = codes.next();
Term term = attributeType.getTermByCode(code).get();
if (!first) {
builder.append(",");
}
builder.append(term.getLabel());
first = false;
}
return builder.toString();
}
}
return null;
}
Aggregations