public static boolean isDraftEnabledEntity(String entityName, String serviceName) { JsonNode csn = getCsn(); if (csn == null) return false; JsonNode draftEnabled = csn.get("definitions").get(serviceName + "." + entityName).get(DRAFT_ENABLED); return draftEnabled != null && "true".equals(draftEnabled.asText()); }
public static boolean isDefaultOrderEnabled(String entityName, String serviceName) { JsonNode csn = getCsn(); if (csn == null) return false; JsonNode orderEnabled = csn.get("definitions").get(serviceName + "." + entityName); if (orderEnabled != null) { return orderEnabled.get(ORDER_DEFAULT) != null && orderEnabled.get(ORDER_DEFAULT).asText().equals("true"); } else { return false; } }
public static boolean isUpdatable(String serviceName, String entityName) throws CSNNotSetException { JsonNode csn = getCsn(); if (csn == null) return true; JsonNode updatable = csn.get("definitions").get(serviceName + "." + entityName) .get("@Capabilities.UpdateRestrictions.Updatable"); return updatable == null || updatable.asText().equals("true"); }
public static boolean isDeletable(String serviceName, String entityName) throws CSNNotSetException { JsonNode csn = getCsn(); if (csn == null) return true; JsonNode deletable = csn.get("definitions").get(serviceName + "." + entityName) .get("@Capabilities.DeleteRestrictions.Deletable"); return deletable == null || deletable.asText().equals("true"); }
public static boolean isDraftNodeEntity(String entityName,String serviceName) { JsonNode csn = getCsn(); if(csn == null){ return false; } JsonNode draftEnabled = csn.get("definitions").get(serviceName + "." + entityName).get(DRAFT_NODE); return draftEnabled != null && "draftPrepare".equals(draftEnabled.asText()); }
public static boolean isHdbcdsMapping() { JsonNode csn = getCsn(); if (csn == null) return false; String sqlMapping = csn.get(SQL_MAPPING) == null ? null : csn.get(SQL_MAPPING).asText(); return sqlMapping != null && sqlMapping.equals("hdbcds"); }
public static String getCDSDataType(String entityName, String serviceName, String propName) { JsonNode entityNode = getCsn().get("definitions").get(serviceName + "." + entityName); if (entityNode != null) { return entityNode.get("elements").get(propName).get("type").asText(); } return null; }
public static boolean isCreatable(String serviceName, String entityName) throws CSNNotSetException { JsonNode csn = getCsn(); if (csn == null) return true; JsonNode insertable = csn.get("definitions").get(serviceName + "." + entityName) .get("@Capabilities.InsertRestrictions.Insertable"); return insertable == null || insertable.asText().equals("true"); }
public static boolean isPlainSqlMapping() { JsonNode csn = getCsn(); if (csn == null) return false; String sqlMapping = csn.get(SQL_MAPPING) == null ? null : csn.get(SQL_MAPPING).asText(); if (sqlMapping != null) return sqlMapping.equals("plain"); else { String csnVersion = csn.get("version").get("csn").asText(); logger.debug("Csn version is " + csnVersion); int versionNumber = Integer.parseInt(csnVersion.replaceAll("\\.", "")); return versionNumber >= 10; } }
/** * Returns the value @cds.persistence.name annotation if present in the csn for * the passed element. If not present this method returns null. * * @param fqEntityName * @param elementName * @return */ public static String getPersistenceName(String fqEntityName, String elementName) { JsonNode csn = getCsn(); if (csn == null) return null; JsonNode elementNode = csn.get("definitions").get(fqEntityName); if (elementNode == null) return null; if (elementName != null) elementNode = elementNode.get("elements").get(elementName); if (elementNode == null) return null; return elementNode.get(CDS_PERSISTENCE_NAME) == null ? null : elementNode.get(CDS_PERSISTENCE_NAME).asText(); }
public static String getEntityName(String serviceName, String parentEntityName, String associationName) { JsonNode csn = getCsn(); if (csn == null) return null; String entityName = null; JsonNode entityNode = csn.get("definitions").get(serviceName + "." + parentEntityName); if (entityNode != null) { JsonNode propertyNode = entityNode.get("elements"); JsonNode associationNode = propertyNode.get(associationName); if (associationNode != null) { entityName = associationNode.get(TARGET).asText(); if (entityName != null && entityName.contains(".")) { entityName = entityName.substring(entityName.lastIndexOf('.') + 1); } } } return entityName; }
public static List<String> getSearchableProperties(String serviceName, String entityName) { JsonNode csn = getCsn(); List<String> searchableProperties = new ArrayList<>(); if (csn != null) { JsonNode entityNode = csn.get("definitions").get(serviceName + "." + entityName); if (entityNode != null && entityNode.get(ODATA_SEARCHABLE) != null && entityNode.get(ODATA_SEARCHABLE).asBoolean()) { JsonNode propertyNode = entityNode.get("elements"); Iterator<String> it = propertyNode.fieldNames(); while (it.hasNext()) { String colName = it.next(); JsonNode defaultSearchNode = propertyNode.get(colName).get(ODATA_DEFAULT_SEARCH_ELEMENT); if (defaultSearchNode != null && defaultSearchNode.asBoolean()) { searchableProperties.add(colName); } } return searchableProperties.isEmpty() ? null : searchableProperties; } } return null; }
public static Map<String, Double> getSearchablePropertiesWithFuzzy(String serviceName, String entityName) { Map<String, Double> searchableFuzzyProperties = new HashMap<>(); JsonNode csn = getCsn(); if (csn != null) { JsonNode entityNode = csn.get("definitions").get(serviceName + "." + entityName); if (entityNode != null && entityNode.get(ODATA_SEARCHABLE) != null && entityNode.get(ODATA_SEARCHABLE).asBoolean()) { JsonNode propertyNode = entityNode.get("elements"); Iterator<String> it = propertyNode.fieldNames(); while (it.hasNext()) { String colName = it.next(); JsonNode defaultSearchNode = propertyNode.get(colName).get(ODATA_DEFAULT_SEARCH_ELEMENT_WITH_FUZZY); if (defaultSearchNode != null) { searchableFuzzyProperties.put(colName.toLowerCase(), Double.parseDouble(defaultSearchNode.asText())); } } return searchableFuzzyProperties.isEmpty() ? null : searchableFuzzyProperties; } return null; } return null; }
public static Set<String> getProperties(String serviceName, String entityName) { LinkedHashSet<String> properties = new LinkedHashSet<>(); JsonNode csn = getCsn(); if (csn != null) { JsonNode entityNode = csn.get("definitions").get(serviceName + "." + entityName); if (entityNode != null) { JsonNode propertyNode = entityNode.get("elements"); Iterator<String> it = propertyNode.fieldNames(); while (it.hasNext()) { String colName = it.next(); String elementType = propertyNode.get(colName).get("type").asText(); if (elementType != null && !elementType.contains("Association") && !elementType.contains("Composition")) { properties.add(colName); } } return properties.isEmpty() ? null : properties; } } return properties; }
/** * Reads authorization (@requires/@restrict) details of the given service/entity * name from CSN.json. * * @throws IllegalArgumentException - If conversion fails due to incompatible * type; check CSN.json and * AuthorizationDetails- class. * @param serviceOrEntityName * @return AuthorizationDetails if found. Else returns null. */ public static AuthorizationDetails getAuthorizationDetails(String serviceOrEntityName) { JsonNode csn = getCsn(); if (csn != null) { JsonNode entityNode = csn.get("definitions").get(serviceOrEntityName); if (entityNode != null) { return getAuthorizationDetails(entityNode); } } return null; }
public static synchronized Map<String,List<String>> getCompositionTree(String serviceName,String entityName) { JsonNode csn = getCsn(); if (csn == null) return null; JsonNode entityNode = csn.get("definitions").get(serviceName + "." + entityName); Map.Entry<String, JsonNode> rootEntry=new Entry<String, JsonNode>() { @Override public JsonNode setValue(JsonNode value) { return null; } @Override public JsonNode getValue() { return entityNode; } @Override public String getKey() { return serviceName + "." + entityName; } }; return constructCompositionTree(rootEntry, serviceName); }
public static synchronized Map<String,List<String>> getDraftTree(String serviceName) { if(draftTree!=null && draftTree.get(serviceName)!=null ) { return draftTree.get(serviceName); } JsonNode csn = getCsn(); if (csn == null) return new HashMap<>(); //current assumption .. only one Draft Tree per Service Map.Entry<String, JsonNode> root=null; JsonNode alldefs = csn.get("definitions"); Iterator<Entry<String, JsonNode>> nodes = alldefs.fields(); while (nodes.hasNext()) { Map.Entry<String, JsonNode> entry = (Map.Entry<String, JsonNode>) nodes.next(); if(entry.getKey().startsWith(serviceName)&&entry.getValue().get(DRAFT_ENABLED)!= null&&entry.getValue().get(DRAFT_ENABLED).asText().equals("true")) { root=entry; break; } } if(root!=null && draftTree!=null) { draftTree.put(serviceName,constructCompositionTree(root, serviceName)); } return draftTree!=null?draftTree.get(serviceName):null; }
private static Map<String,List<String>> constructCompositionTree(Map.Entry<String, JsonNode> currentNode,String serviceName){ Map<String,List<String>> draftTree=new HashMap<>(); List<String> compositions=new ArrayList<>(); JsonNode csn = getCsn(); if (csn == null) return draftTree;
public static Map<String, AdminDataAnnotation> getAdminDataMapForCreate(String serviceName, String entityName, boolean userContextPresent) { JsonNode csn = getCsn(); if (csn == null) return null;
public static Map<String, AdminDataAnnotation> getAdminDataMapForUpdate(String serviceName, String entityName, boolean userContextPresent) { JsonNode csn = getCsn(); if (csn == null) return null;