diff --git a/platform-core/src/main/java/com/webank/wecube/platform/core/model/workflow/DmeOutputParamAttr.java b/platform-core/src/main/java/com/webank/wecube/platform/core/model/workflow/DmeOutputParamAttr.java index 5caa8aa64b..99bcd3cdcb 100644 --- a/platform-core/src/main/java/com/webank/wecube/platform/core/model/workflow/DmeOutputParamAttr.java +++ b/platform-core/src/main/java/com/webank/wecube/platform/core/model/workflow/DmeOutputParamAttr.java @@ -4,6 +4,7 @@ import com.webank.wecube.platform.core.entity.plugin.PluginConfigInterfaceParameters; import com.webank.wecube.platform.core.entity.plugin.PluginConfigInterfaces; +import com.webank.wecube.platform.core.service.dme.EntityQueryExpr; import com.webank.wecube.platform.core.service.dme.EntityQueryExprNodeInfo; public class DmeOutputParamAttr { @@ -14,6 +15,8 @@ public class DmeOutputParamAttr { private Object retVal; private boolean processed; private List exprNodeInfos; + private EntityQueryExpr entityQueryExpr; + public PluginConfigInterfaces getInterf() { return interf; } @@ -64,5 +67,12 @@ public boolean isRootEntityAttr(){ return false; } + public EntityQueryExpr getEntityQueryExpr() { + return entityQueryExpr; + } + public void setEntityQueryExpr(EntityQueryExpr entityQueryExpr) { + this.entityQueryExpr = entityQueryExpr; + } + } diff --git a/platform-core/src/main/java/com/webank/wecube/platform/core/service/dme/EntityOperationContext.java b/platform-core/src/main/java/com/webank/wecube/platform/core/service/dme/EntityOperationContext.java index cc7d7de0e5..86698cd205 100644 --- a/platform-core/src/main/java/com/webank/wecube/platform/core/service/dme/EntityOperationContext.java +++ b/platform-core/src/main/java/com/webank/wecube/platform/core/service/dme/EntityOperationContext.java @@ -22,6 +22,8 @@ public class EntityOperationContext { protected EntityDataRouteFactory entityDataRouteFactory; protected Map externalCacheMap; + + protected EntityQueryExpr entityQueryExpr; public EntityQueryLinkNode getHeadEntityQueryLinkNode() { return headEntityQueryLinkNode; @@ -112,4 +114,12 @@ public void setExternalCacheMap(Map externalCacheMap) { this.externalCacheMap = externalCacheMap; } + public EntityQueryExpr getEntityQueryExpr() { + return entityQueryExpr; + } + + public void setEntityQueryExpr(EntityQueryExpr entityQueryExpr) { + this.entityQueryExpr = entityQueryExpr; + } + } diff --git a/platform-core/src/main/java/com/webank/wecube/platform/core/service/dme/StandardEntityOperationRestClient.java b/platform-core/src/main/java/com/webank/wecube/platform/core/service/dme/StandardEntityOperationRestClient.java index 91de4ac056..8db36a2961 100644 --- a/platform-core/src/main/java/com/webank/wecube/platform/core/service/dme/StandardEntityOperationRestClient.java +++ b/platform-core/src/main/java/com/webank/wecube/platform/core/service/dme/StandardEntityOperationRestClient.java @@ -9,6 +9,10 @@ import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.ResponseEntity; import org.springframework.web.client.RestTemplate; import com.fasterxml.jackson.core.JsonProcessingException; @@ -83,15 +87,25 @@ public StandardEntityOperationResponseDto query(EntityRouteDescription entityDef // POST List> public StandardEntityOperationResponseDto update(EntityRouteDescription entityDef, - List recordsToUpdate) { + List recordsToUpdate,Map additionalRequestHeaders) { URI requestUri = buildStandardOperationUri(entityDef, getUpdateUriTemplate()); - + List> requestBody = convertToMapList(recordsToUpdate); + + HttpHeaders headers = new HttpHeaders(); + if(additionalRequestHeaders != null) { + for(String headerKey : additionalRequestHeaders.keySet()) { + headers.add(headerKey, additionalRequestHeaders.get(headerKey)); + } + } + + HttpEntity>> requestEntity = new HttpEntity<>(requestBody, headers); long timeMilliSeconds = System.currentTimeMillis(); log.info("SEND UPDATE post [{}] url={}, request={}", timeMilliSeconds, requestUri.toString(), toJson(requestBody)); - StandardEntityOperationResponseDto result = getRestTemplate().postForObject(requestUri, requestBody, + ResponseEntity respEntity = getRestTemplate().exchange(requestUri, HttpMethod.POST, requestEntity, StandardEntityOperationResponseDto.class); + StandardEntityOperationResponseDto result = respEntity.getBody(); log.debug("RECEIVE UPDATE post [{}] url={},result={}", timeMilliSeconds, requestUri.toString(), result); if(!StandardEntityOperationResponseDto.STATUS_OK.equalsIgnoreCase(result.getStatus())) { log.error("update failed with error:{} {}", result.getStatus(), result.getMessage()); @@ -100,14 +114,25 @@ public StandardEntityOperationResponseDto update(EntityRouteDescription entityDe return result; } - public StandardEntityOperationResponseDto updateData(EntityRouteDescription entityDef,List> recordsToUpdate) { + public StandardEntityOperationResponseDto updateData(EntityRouteDescription entityDef,List> recordsToUpdate, Map additionalRequestHeaders) { URI requestUri = buildStandardOperationUri(entityDef, getUpdateUriTemplate()); + + HttpHeaders headers = new HttpHeaders(); + if(additionalRequestHeaders != null) { + for(String headerKey : additionalRequestHeaders.keySet()) { + headers.add(headerKey, additionalRequestHeaders.get(headerKey)); + } + } + + HttpEntity>> requestEntity = new HttpEntity<>(recordsToUpdate, headers); long timeMilliSeconds = System.currentTimeMillis(); log.info("SEND UPDATE post [{}] url={}, request={}", timeMilliSeconds, requestUri.toString(), toJson(recordsToUpdate)); - StandardEntityOperationResponseDto result = getRestTemplate().postForObject(requestUri, recordsToUpdate, + ResponseEntity respEntity = getRestTemplate().exchange(requestUri, HttpMethod.POST, requestEntity, StandardEntityOperationResponseDto.class); + + StandardEntityOperationResponseDto result = respEntity.getBody(); log.debug("RECEIVE UPDATE post [{}] url={},result={}", timeMilliSeconds, requestUri.toString(), result); if(!StandardEntityOperationResponseDto.STATUS_OK.equalsIgnoreCase(result.getStatus())) { diff --git a/platform-core/src/main/java/com/webank/wecube/platform/core/service/dme/StandardEntityOperationService.java b/platform-core/src/main/java/com/webank/wecube/platform/core/service/dme/StandardEntityOperationService.java index 5ab627dc89..fb62da3cc9 100644 --- a/platform-core/src/main/java/com/webank/wecube/platform/core/service/dme/StandardEntityOperationService.java +++ b/platform-core/src/main/java/com/webank/wecube/platform/core/service/dme/StandardEntityOperationService.java @@ -170,6 +170,7 @@ protected EntityOperationContext buildEntityOperationContext(EntityOperationRoot List exprNodeInfos = entityQueryExpr.getExprNodeInfos(); EntityOperationContext ctx = new EntityOperationContext(); + ctx.setEntityQueryExpr(entityQueryExpr); ctx.setEntityQueryExprNodeInfos(exprNodeInfos); ctx.setOriginalEntityLinkExpression(condition.getEntityLinkExpr()); ctx.setOriginalEntityData(condition.getEntityIdentity()); diff --git a/platform-core/src/main/java/com/webank/wecube/platform/core/service/dme/StandardEntityQueryExecutor.java b/platform-core/src/main/java/com/webank/wecube/platform/core/service/dme/StandardEntityQueryExecutor.java index d709bde36b..8e2886885b 100644 --- a/platform-core/src/main/java/com/webank/wecube/platform/core/service/dme/StandardEntityQueryExecutor.java +++ b/platform-core/src/main/java/com/webank/wecube/platform/core/service/dme/StandardEntityQueryExecutor.java @@ -2,6 +2,7 @@ import java.util.ArrayList; import java.util.Collections; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -145,9 +146,15 @@ public void executeUpdate(EntityOperationContext ctx, Object valueToUpdate) { EntityQueryExprNodeInfo nodeInfo = leafLinkNode.getExprNodeInfo(); EntityRouteDescription entityDef = ctx.getEntityDataRouteFactory() .deduceEntityDescription(nodeInfo.getPackageName(), nodeInfo.getEntityName()); + + Map additionalRequestHeaders = new HashMap<>(); + + if(ctx.getEntityQueryExpr()!= null && StringUtils.isNoneBlank(ctx.getEntityQueryExpr().getExprOperation())) { + additionalRequestHeaders.put("operation", ctx.getEntityQueryExpr().getExprOperation()); + } StandardEntityOperationRestClient restClient = ctx.getStandardEntityOperationRestClient(); - restClient.update(entityDef, entityDataRecordsToUpdate); + restClient.update(entityDef, entityDataRecordsToUpdate, additionalRequestHeaders); } public EntityQueryLinkNode buildEntityQueryLinkNode(List exprNodeInfos) { diff --git a/platform-core/src/main/java/com/webank/wecube/platform/core/service/workflow/PluginInvocationService.java b/platform-core/src/main/java/com/webank/wecube/platform/core/service/workflow/PluginInvocationService.java index 1c7862c945..38bc1fac37 100644 --- a/platform-core/src/main/java/com/webank/wecube/platform/core/service/workflow/PluginInvocationService.java +++ b/platform-core/src/main/java/com/webank/wecube/platform/core/service/workflow/PluginInvocationService.java @@ -59,6 +59,7 @@ import com.webank.wecube.platform.core.service.dme.EntityDataAttr; import com.webank.wecube.platform.core.service.dme.EntityDataRecord; import com.webank.wecube.platform.core.service.dme.EntityOperationRootCondition; +import com.webank.wecube.platform.core.service.dme.EntityQueryExpr; import com.webank.wecube.platform.core.service.dme.EntityQueryExprNodeInfo; import com.webank.wecube.platform.core.service.dme.EntityRouteDescription; import com.webank.wecube.platform.core.service.dme.EntityTreeNodesOverview; @@ -687,7 +688,7 @@ private void tryProcessDataIdProcExecBinding(String bindDataId, WorkflowInstCrea StandardEntityOperationRestClient restClient = new StandardEntityOperationRestClient(jwtSsoRestTemplate); - StandardEntityOperationResponseDto resultDto = restClient.update(entityDef, recordsToUpdate); + StandardEntityOperationResponseDto resultDto = restClient.update(entityDef, recordsToUpdate, null); if (StandardEntityOperationResponseDto.STATUS_ERROR.equals(resultDto.getStatus())) { log.error("errors to update entity:{}", resultDto.getMessage()); return; @@ -3779,7 +3780,8 @@ private void tryHandleSingleOutputMapOnceEntityCreation(PluginInterfaceInvocatio // continue; } - List exprNodeInfos = entityQueryExpressionParser.parse(paramExpr).getExprNodeInfos(); + EntityQueryExpr entityQueryExpr = entityQueryExpressionParser.parse(paramExpr); + List exprNodeInfos = entityQueryExpr.getExprNodeInfos(); if (exprNodeInfos == null || exprNodeInfos.isEmpty()) { String errMsg = String.format("Unknown how to update entity attribute due to invalid expression:%s", @@ -3804,6 +3806,7 @@ private void tryHandleSingleOutputMapOnceEntityCreation(PluginInterfaceInvocatio outputParamAttr.setParamExpr(paramExpr); outputParamAttr.setParamName(paramName); outputParamAttr.setRetVal(finalRetVal); + outputParamAttr.setEntityQueryExpr(entityQueryExpr); allDmeOutputParamAttrs.add(outputParamAttr); if (outputParamAttr.isRootEntityAttr()) { @@ -3855,7 +3858,7 @@ private void tryHandleSingleOutputMapOnceEntityCreation(PluginInterfaceInvocatio this.jwtSsoRestTemplate); List> objDataMaps = new ArrayList<>(); objDataMaps.add(objDataMap); - restClient.updateData(entityDef, objDataMaps); + restClient.updateData(entityDef, objDataMaps, null); } else { if (verifyIfHasNormalEntityMappingExcludeAssign(rootDemOutputParamAttrs)) {