Search in sources :

Example 11 with MdAttributeDAOIF

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++;
            }
        }
    }
}
Also used : MdAttributeDAOIF(com.runwaysdk.dataaccess.MdAttributeDAOIF) JsonObject(com.google.gson.JsonObject)

Example 12 with MdAttributeDAOIF

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);
}
Also used : MdVertexDAOIF(com.runwaysdk.dataaccess.MdVertexDAOIF) GraphRequest(com.runwaysdk.dataaccess.graph.GraphRequest) MdAttributeDAOIF(com.runwaysdk.dataaccess.MdAttributeDAOIF) HashMap(java.util.HashMap) VertexObject(com.runwaysdk.business.graph.VertexObject) VertexServerGeoObject(net.geoprism.registry.model.graph.VertexServerGeoObject) GraphDBService(com.runwaysdk.dataaccess.graph.GraphDBService)

Example 13 with MdAttributeDAOIF

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();
    }
}
Also used : MdVertexDAOIF(com.runwaysdk.dataaccess.MdVertexDAOIF) MdAttributeDAOIF(com.runwaysdk.dataaccess.MdAttributeDAOIF) VertexObject(com.runwaysdk.business.graph.VertexObject) GraphQuery(com.runwaysdk.business.graph.GraphQuery)

Example 14 with MdAttributeDAOIF

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);
}
Also used : LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) GeoObjectType(org.commongeoregistry.adapter.metadata.GeoObjectType) MdAttributeDAOIF(com.runwaysdk.dataaccess.MdAttributeDAOIF) MdAttributeTermDAOIF(com.runwaysdk.dataaccess.MdAttributeTermDAOIF) Term(org.commongeoregistry.adapter.Term) AttributeTermType(org.commongeoregistry.adapter.metadata.AttributeTermType) Test(org.junit.Test) ClassificationTypeTest(net.geoprism.registry.classification.ClassificationTypeTest)

Example 15 with MdAttributeDAOIF

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;
}
Also used : CompositeRestriction(net.geoprism.registry.query.graph.CompositeRestriction) MdEdgeDAOIF(com.runwaysdk.dataaccess.MdEdgeDAOIF) JsonObject(com.google.gson.JsonObject) Term(org.commongeoregistry.adapter.Term) Classifier(net.geoprism.ontology.Classifier) AttributeClassificationType(org.commongeoregistry.adapter.metadata.AttributeClassificationType) ClassificationType(net.geoprism.registry.model.ClassificationType) AttributeClassificationType(org.commongeoregistry.adapter.metadata.AttributeClassificationType) Date(java.util.Date) AttributeDateType(org.commongeoregistry.adapter.metadata.AttributeDateType) AttributeValueRestriction(net.geoprism.registry.query.graph.AttributeValueRestriction) JsonArray(com.google.gson.JsonArray) MdClassificationDAOIF(com.runwaysdk.dataaccess.MdClassificationDAOIF) MdAttributeDAOIF(com.runwaysdk.dataaccess.MdAttributeDAOIF) AttributeType(org.commongeoregistry.adapter.metadata.AttributeType) Classification(net.geoprism.registry.model.Classification) AttributeBooleanType(org.commongeoregistry.adapter.metadata.AttributeBooleanType) AttributeTermType(org.commongeoregistry.adapter.metadata.AttributeTermType)

Aggregations

MdAttributeDAOIF (com.runwaysdk.dataaccess.MdAttributeDAOIF)32 MdVertexDAOIF (com.runwaysdk.dataaccess.MdVertexDAOIF)24 GraphQuery (com.runwaysdk.business.graph.GraphQuery)23 VertexObject (com.runwaysdk.business.graph.VertexObject)9 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)9 JsonObject (com.google.gson.JsonObject)7 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)7 LinkedList (java.util.LinkedList)7 VertexServerGeoObject (net.geoprism.registry.model.graph.VertexServerGeoObject)7 Date (java.util.Date)5 JsonArray (com.google.gson.JsonArray)4 HashMap (java.util.HashMap)4 LocalizedValue (org.commongeoregistry.adapter.dataaccess.LocalizedValue)4 MdVertexDAO (com.runwaysdk.dataaccess.metadata.graph.MdVertexDAO)3 Page (net.geoprism.registry.view.Page)3 AttributeType (org.commongeoregistry.adapter.metadata.AttributeType)3 GsonBuilder (com.google.gson.GsonBuilder)2 MdAttributeTermDAOIF (com.runwaysdk.dataaccess.MdAttributeTermDAOIF)2 MdEdgeDAOIF (com.runwaysdk.dataaccess.MdEdgeDAOIF)2 ProgrammingErrorException (com.runwaysdk.dataaccess.ProgrammingErrorException)2