use of com.runwaysdk.dataaccess.MdAttributeDAOIF in project geoprism-registry by terraframe.
the class AbstractGraphPageQuery method addCriteria.
private void addCriteria(final MdVertexDAOIF mdVertex, JsonObject filters, StringBuilder statement, Map<String, Object> parameters) {
Iterator<String> keys = filters.keySet().iterator();
int i = 0;
while (keys.hasNext()) {
String attributeName = keys.next();
MdAttributeDAOIF mdAttribute = mdVertex.definesAttribute(attributeName);
if (mdAttribute != null) {
String columnName = this.getColumnName(mdAttribute);
JsonObject filter = filters.get(attributeName).getAsJsonObject();
String mode = filter.get("matchMode").getAsString();
if (mode.equals("between")) {
JsonObject value = filter.get("value").getAsJsonObject();
if (value.has("startDate") && !value.get("startDate").isJsonNull()) {
String date = value.get("startDate").getAsString();
if (date.length() > 0) {
parameters.put(attributeName + "StartDate", GeoRegistryUtil.parseDate(date));
statement.append(((i == 0) ? " WHERE " : " AND ") + columnName + " >= :" + attributeName + "StartDate");
i++;
}
}
if (value.has("endDate") && !value.get("endDate").isJsonNull()) {
String date = value.get("endDate").getAsString();
if (date.length() > 0) {
parameters.put(attributeName + "EndDate", GeoRegistryUtil.parseDate(date));
statement.append(((i == 0) ? " WHERE " : " AND ") + columnName + " <= :" + attributeName + "EndDate");
i++;
}
}
} else if (mode.equals("contains")) {
parameters.put(attributeName, "%" + filter.get("value").getAsString().toUpperCase() + "%");
statement.append(((i == 0) ? " WHERE " : " AND ") + columnName + ".toUpperCase() LIKE :" + attributeName);
i++;
} else if (mode.equals("equals")) {
parameters.put(attributeName, filter.get("value").getAsString());
statement.append(((i == 0) ? " WHERE " : " AND ") + columnName + " = :" + attributeName);
i++;
}
}
}
}
use of com.runwaysdk.dataaccess.MdAttributeDAOIF in project geoprism-registry by terraframe.
the class SearchService method clear.
// @Transaction
public void clear(String vertexType) {
String suffix = this.getSuffix();
MdVertexDAOIF mdVertex = MdVertexDAO.getMdVertexDAO(PACKAGE + "." + VERTEX_PREFIX + suffix);
MdAttributeDAOIF mdVertexType = mdVertex.definesAttribute(VERTEX_TYPE);
StringBuilder statement = new StringBuilder();
statement.append("DELETE VERTEX " + mdVertex.getDBClassName());
statement.append(" WHERE " + mdVertexType.getColumnName() + " = :vertexType");
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("vertexType", vertexType);
GraphDBService service = GraphDBService.getInstance();
GraphRequest request = service.getGraphDBRequest();
GraphRequest ddlRequest = service.getDDLGraphDBRequest();
service.ddlCommand(request, ddlRequest, statement.toString(), parameters);
}
use of com.runwaysdk.dataaccess.MdAttributeDAOIF in project geoprism-registry by terraframe.
the class SearchService method remove.
// @Transaction
public void remove(String code) {
// String suffix = this.getSuffix();
//
// MdVertexDAOIF mdVertex = MdVertexDAO.getMdVertexDAO(PACKAGE + "." +
// VERTEX_PREFIX + suffix);
// MdAttributeDAOIF mdCode = mdVertex.definesAttribute(CODE);
//
// StringBuilder statement = new StringBuilder();
// statement.append("DELETE VERTEX " + mdVertex.getDBClassName());
// statement.append(" WHERE " + mdCode.getColumnName() + " = :code");
//
// Map<String, Object> parameters = new HashMap<String, Object>();
// parameters.put("code", code);
//
// GraphDBService service = GraphDBService.getInstance();
// GraphRequest request = service.getGraphDBRequest();
//
// service.command(request, statement.toString(), parameters);
String suffix = this.getSuffix();
MdVertexDAOIF mdVertex = MdVertexDAO.getMdVertexDAO(PACKAGE + "." + VERTEX_PREFIX + suffix);
MdAttributeDAOIF mdCode = mdVertex.definesAttribute(CODE);
StringBuilder statement = new StringBuilder();
statement.append("SELECT FROM " + mdVertex.getDBClassName());
statement.append(" WHERE :code = " + mdCode.getColumnName());
GraphQuery<VertexObject> query = new GraphQuery<VertexObject>(statement.toString());
query.setParameter("code", code);
List<VertexObject> results = query.getResults();
for (VertexObject result : results) {
result.delete();
}
}
use of com.runwaysdk.dataaccess.MdAttributeDAOIF in project geoprism-registry by terraframe.
the class AttributeTypeServiceTest method testCreateGeoObjectTypeTerm.
@Test
public void testCreateGeoObjectTypeTerm() {
String organizationCode = FastTestDataset.ORG_CGOV.getCode();
GeoObjectType province = MetadataFactory.newGeoObjectType(TEST_GOT.getCode(), GeometryType.POLYGON, new LocalizedValue("Province"), new LocalizedValue(""), true, organizationCode, testData.adapter);
String geoObjectTypeCode = province.getCode();
AttributeTermType attributeTermType = (AttributeTermType) AttributeType.factory("testTerm", new LocalizedValue("Test Term Name"), new LocalizedValue("Test Term Description"), AttributeTermType.TYPE, false, false, false);
Term term = new Term(TEST_GOT.getCode() + "_" + "testTerm", new LocalizedValue("Test Term Name"), new LocalizedValue("Test Term Description"));
attributeTermType.setRootTerm(term);
province.addAttribute(attributeTermType);
String gtJSON = province.toJSON().toString();
testData.adapter.createGeoObjectType(gtJSON);
String attributeTypeJSON = attributeTermType.toJSON().toString();
attributeTermType = (AttributeTermType) testData.adapter.createAttributeType(geoObjectTypeCode, attributeTypeJSON);
MdAttributeDAOIF mdAttributeConcreteDAOIF = checkAttribute(TEST_GOT.getCode(), attributeTermType.getName());
Assert.assertNotNull("A GeoObjectType did not define the attribute: " + attributeTermType.getName(), mdAttributeConcreteDAOIF);
Assert.assertTrue("A GeoObjectType did not define the attribute of the correct type: " + mdAttributeConcreteDAOIF.getType(), mdAttributeConcreteDAOIF instanceof MdAttributeTermDAOIF);
Term rootTerm = attributeTermType.getRootTerm();
Term childTerm1 = new Term("termValue1", new LocalizedValue("Term Value 1"), new LocalizedValue(""));
Term childTerm2 = new Term("termValue2", new LocalizedValue("Term Value 2"), new LocalizedValue(""));
testData.adapter.createTerm(rootTerm.getCode(), childTerm1.toJSON().toString());
testData.adapter.createTerm(rootTerm.getCode(), childTerm2.toJSON().toString());
province = testData.adapter.getGeoObjectTypes(new String[] { TEST_GOT.getCode() }, null, PermissionContext.READ)[0];
AttributeTermType attributeTermType2 = (AttributeTermType) province.getAttribute("testTerm").get();
// Check to see if the cache was updated.
checkTermsCreate(attributeTermType2);
attributeTermType.setLabel(MdAttributeLocalInfo.DEFAULT_LOCALE, "Test Term Name Update");
attributeTermType.setDescription(MdAttributeLocalInfo.DEFAULT_LOCALE, "Test Term Description Update");
attributeTermType = (AttributeTermType) testData.adapter.updateAttributeType(geoObjectTypeCode, attributeTermType.toJSON().toString());
Assert.assertEquals(attributeTermType.getLabel().getValue(), "Test Term Name Update");
Assert.assertEquals(attributeTermType.getDescription().getValue(), "Test Term Description Update");
checkTermsCreate(attributeTermType);
// Test updating the term
childTerm2 = new Term("termValue2", new LocalizedValue("Term Value 2a"), new LocalizedValue(""));
testData.adapter.updateTerm(rootTerm.getCode(), childTerm2.toJSON().toString());
province = testData.adapter.getGeoObjectTypes(new String[] { TEST_GOT.getCode() }, null, PermissionContext.READ)[0];
AttributeTermType attributeTermType3 = (AttributeTermType) province.getAttribute("testTerm").get();
checkTermsUpdate(attributeTermType3);
testData.adapter.deleteTerm(rootTerm.getCode(), "termValue2");
province = testData.adapter.getGeoObjectTypes(new String[] { TEST_GOT.getCode() }, null, PermissionContext.READ)[0];
attributeTermType3 = (AttributeTermType) province.getAttribute("testTerm").get();
System.out.println(attributeTermType3.getRootTerm().toString());
checkTermsDelete(attributeTermType3);
}
use of com.runwaysdk.dataaccess.MdAttributeDAOIF 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;
}
Aggregations