public static UriInfoImpl constructDeepReadForDraftRoot(EdmEntitySet edmEntitySet, String serviceName) throws ODataException { UriInfoImpl uriInfoForRead = new UriInfoImpl(); uriInfoForRead.setStartEntitySet(edmEntitySet); uriInfoForRead.setTargetEntitySet(edmEntitySet); Map<String,List<String>> draftTree = CSNUtil.getDraftTree(serviceName); List<ArrayList<NavigationPropertySegment>> expandOption = new ArrayList<>(); constructDraftTreeExpand(edmEntitySet, serviceName, draftTree, new ArrayList<>(), expandOption); uriInfoForRead.setExpand(expandOption); return uriInfoForRead; }
if(CSNUtil.isDraftEnabledEntity(entity.getName(), schema)|| CSNUtil.isDraftNodeEntity(entity.getName(), schema)) { Column col = formNewColumnObject(entity, DraftUtilsV4.DRAFTS_FOREIGN_KEY, dbalias, false, parentComplexName, eInfo); columns.add(col);
/** * Returns the csn for the current call. This method logs if the csn is null. Actual handling for the * null csn scenario is to be done in the calling method. */ private static JsonNode getCsn() { if (csnForCurrentThread.get() != null) { return csnForCurrentThread.get(); } try { checkIfCSNInitialized(); } catch (CSNNotSetException e) { logger.error(CSN_NOT_FOUND, e); } return staticCsn; }
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); }
private static AuthorizationDetails getAuthorizationDetails(JsonNode entityNode) { Map<String, Object> authDetails = new HashMap<>(); if (entityNode.get(KIND) != null) { if (entityNode.get(KIND).asText().equals("service")) { authDetails.put(KIND, entityNode.get(KIND)); authDetails.put("requires", entityNode.get("@requires")); return getAuthorizationDetailsPojo(authDetails); } else if (entityNode.get(KIND).asText().equals("entity")) { authDetails.put(KIND, entityNode.get(KIND)); JsonNode restrictDetails = entityNode.get(RESTRICT); // handle to convert str to array to make it consistent. convertToArray(restrictDetails); authDetails.put("restrict", entityNode.get(RESTRICT)); return getAuthorizationDetailsPojo(authDetails); } } return null; }
public static Map<String, AdminDataAnnotation> getAdminDataMapForCreate(String serviceName, String entityName, boolean userContextPresent) { JsonNode csn = getCsn(); if (csn == null) return null; if (insertNode != null && insertNode.get(ODATA_HASH) != null) { adminDataMap.put(colName, getAdminDataAnnotation(insertNode.get(ODATA_HASH).asText(), userContextPresent)); if (cdsinsertNode != null && cdsinsertNode.get(ODATA_HASH) != null) { adminDataMap.put(colName, getAdminDataAnnotation(cdsinsertNode.get(ODATA_HASH).asText(), userContextPresent)); if (updateNode != null && updateNode.get(ODATA_HASH) != null) { adminDataMap.put(colName, getAdminDataAnnotation(updateNode.get(ODATA_HASH).asText(), userContextPresent)); if (cdsupdateNode != null && cdsupdateNode.get(ODATA_HASH) != null) { adminDataMap.put(colName, getAdminDataAnnotation(cdsupdateNode.get(ODATA_HASH).asText(), userContextPresent));
cloned.forEach((key,value)-> { if(value instanceof Map) { String associatedEntity = CSNUtil.getEntityName(serviceName, entityName, key); if(associatedEntity != null && !"".equals(associatedEntity.trim())) { entityDataBuilder.addAssociationElement(key, createFromDeepMap(serviceName, (Map<String, Object>)value, keys, associatedEntity, key)); String associatedEntity = CSNUtil.getEntityName(serviceName, entityName, key); List<Map<String, Object>> valueList = (List<Map<String, Object>>)value; List<EntityData> edList = new ArrayList<>();
adminDataMapForUpdate = CSNUtil.getAdminDataMapForUpdate(ns, entityName, (conn != null && conn.getClientInfo(APPLICATIONUSER) != null)); } catch (SQLException e2) {
adminDataMapForCreate=CSNUtil.getAdminDataMapForCreate(ns, entityName, (conn!=null&&conn.getClientInfo(APPLICATIONUSER)!=null)); } catch (SQLException e2) { logger.error("Error while fetching admin Data for insert:",e2);
if(CSNUtil.isDraftEnabledEntity(entitySet.getEntityType().getName(), serviceName)) { draftProvider.deleteEntry(uriInfo, context, DraftUtilsV2.DRAFTS_ADMIN_TABLE_NAME, draftAdminDataKeyMap, dataProvider.getDSParams());
entityName = CSNUtil.getEntityName(namespace, parentEntityName, em.getName());
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; }
@Override public final Entity updateEntity(UriInfo uriInfo, DeserializerResult payLoad,ODataRequest request,ODataResponse response) throws ODataApplicationException { this.conn = getConnection(request); UriResourceEntitySet entitySet = ((UriResourceEntitySet)uriInfo.getUriResourceParts().get(0)); String serviceName = entitySet.getEntityType().getNamespace(); Map<String, AdminDataAnnotation> adminDataMapForCreate = null; try{ adminDataMapForCreate = CSNUtil.getAdminDataMapForUpdate(serviceName,entitySet.getEntitySet().getName(),(conn != null && conn.getClientInfo(APPLICATIONUSER) != null)); }catch(SQLException ex){ CDSRuntimeException cdsRuntimeException = new CDSRuntimeException(CDSRuntimeException.MessageKeys.INTERNAL_ERROR, "UPDATE FAILED WITH INTERNAL ERROR", HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), HeaderUtil.getlocale(request), "INSERT FAILED WITH INTERNAL ERROR"); logger.error("INSERT FAILED WITH INTERNAL ERROR", ex); throw cdsRuntimeException; } UpdateEntityInfo uEinfo=cdsprocessor.transormToUpdateEntityInfo(uriInfo, payLoad, request,(request!=null&&request.getMethod()==HttpMethod.PUT)?false:true ,adminDataMapForCreate); cdsprocessor.executeUpdate(uriInfo, uEinfo, conn, request); //--- Read Entity after successful UPdate --- if(isDraftFlow()) { return readDataFromMainTable(uriInfo, request, DraftUtilsV4.extractKeyPredicateFilterExpressions(uriInfo, false)); }else { return readEntity(uriInfo,request,response, false).getEntity(); } }
Map<String, AdminDataAnnotation> adminDataMapForCreate = null; try{ adminDataMapForCreate = CSNUtil.getAdminDataMapForCreate(serviceName,entitySet.getName(),(conn != null && conn.getClientInfo(APPLICATIONUSER) != null)); }catch(SQLException ex){ CDSRuntimeException cdsRuntimeException = new CDSRuntimeException(CDSRuntimeException.MessageKeys.INTERNAL_ERROR,
public static Map<String, AdminDataAnnotation> getAdminDataMapForUpdate(String serviceName, String entityName, boolean userContextPresent) { JsonNode csn = getCsn(); if (csn == null) return null; if (updateNode != null && updateNode.get(ODATA_HASH) != null) { adminDataMap.put(colName, getAdminDataAnnotation(updateNode.get(ODATA_HASH).asText(), userContextPresent)); if (cdsupdateNode != null && cdsupdateNode.get(ODATA_HASH) != null) { adminDataMap.put(colName, getAdminDataAnnotation(cdsupdateNode.get(ODATA_HASH).asText(), userContextPresent));
@Override public IDataProviderResponse readEntity(GetEntityUriInfo uriInfo, ODataContext context) throws ODataException { String entitySetName = uriInfo.getTargetEntitySet().getName(); try{ checkAuthorization(uriInfo,READ); } catch(UnauthorizedException ue){ logger.error("Read operation on this entity not allowed for this user"); return handleAuthorizationException(ue); } List<PathSegment> precedingSegments = context.getPathInfo().getPrecedingSegments(); String serviceName = precedingSegments.get(precedingSegments.size() - 1).getPath(); if(CSNUtil.isDraftEnabledEntity(entitySetName,serviceName)|| CSNUtil.isDraftNodeEntity(entitySetName, serviceName)) { return this.readEntityDraftFlow(uriInfo, context); }else{ return this.readEntityNonDraftFlow(uriInfo, context); } }
public EntityCollection processResultSetForMainTable(ResultSet result, Connection conn,ODataRequest request) throws ODataApplicationException { EntityCollection ec; try { ResultSetProcessor rsp=new ResultSetProcessor(request); ec = rsp.toEntityCollection(result, qHForDraftMainTable.getEntityInfo()); } catch (Exception e) { logger.error(e.getMessage(),e); throw new CDSRuntimeException(CDSRuntimeException.MessageKeys.INTERNAL_ERROR, "Error occured while converting result set to entities:"+ e.getMessage(), HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), HeaderUtil.getlocale(request),e); } Map<String,List<String>> draftTree=CSNUtil.getDraftTree(qHForDraftMainTable.getSchema()); //After getting the resultSet Calculate and append the Calculated fields for Drafts Table for(int i=0;i<ec.getEntities().size();i++) { Entity entityActive=ec.getEntities().get(i); correctionInMainEntities(entityActive, qHForDraftMainTable.getSchema(), draftTree); } return ec; }
private CreateEntityInfo convertEntityDataToEntityInfo(EntityData entityData, String parentEntityName){ CreateEntityInfo ceInfo = new CreateEntityInfo(); EntityMetadata em = ((HasMetadata)entityData).getEntityMetadata(); String entityName = null; if(parentEntityName != null && parentEntityName.length() > 0){ entityName = CSNUtil.getEntityName(namespace, parentEntityName, em.getName()); } if(entityName == null){ entityName = em.getName(); } ceInfo.setEntityName(entityName); List<Column> columns= formAllColumnsFromEntityData(entityData, false); ceInfo.setColumns(columns); return ceInfo; }
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; draftTree.putAll(constructCompositionTree(compositionNode, serviceName));
@Override public IDataProviderResponse updateEntity(PutMergePatchUriInfo uriInfo, ODataEntry content, String requestContentType, boolean merge, ODataContext context) throws ODataException { String entitySetName = uriInfo.getStartEntitySet().getName(); try{ GetEntityUriInfo uInfo = (GetEntityUriInfo) uriInfo; checkAuthorization(uInfo,WRITE); } catch(UnauthorizedException ue){ logger.error("Update operation on this entity not allowed for this user"); return handleAuthorizationException(ue); } List<PathSegment> precedingSegments = context.getPathInfo().getPrecedingSegments(); String serviceName = precedingSegments.get(precedingSegments.size() - 1).getPath(); if(CSNUtil.isDraftEnabledEntity(entitySetName,serviceName)|| CSNUtil.isDraftNodeEntity(entitySetName, serviceName)) { return autoSaveMergeEntityForDraft(uriInfo, content, requestContentType, merge, context); }else{ return updateEntityNonDraftFlow(uriInfo, content, requestContentType, merge, context); } }