Skip to content

Commit

Permalink
Merge pull request #2383 from WeBankPartners/2378_dme_operation
Browse files Browse the repository at this point in the history
2378 dme operation
  • Loading branch information
zgyzgyhero authored Jun 27, 2023
2 parents 9f5262f + 955b2af commit 4f97028
Show file tree
Hide file tree
Showing 22 changed files with 2,115 additions and 1,761 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@

import com.webank.wecube.platform.core.dto.plugin.CommonResponseDto;
import com.webank.wecube.platform.core.dto.plugin.CoreObjectMetaDto;
import com.webank.wecube.platform.core.dto.plugin.ParamMetadataQueryDto;
import com.webank.wecube.platform.core.dto.plugin.PluginConfigDto;
import com.webank.wecube.platform.core.dto.plugin.PluginConfigInterfaceParameterDto;
import com.webank.wecube.platform.core.dto.plugin.PluginConfigRoleRequestDto;
import com.webank.wecube.platform.core.dto.plugin.TargetEntityFilterRuleDto;
import com.webank.wecube.platform.core.service.plugin.PluginConfigMgmtService;
Expand Down Expand Up @@ -165,5 +167,13 @@ public CommonResponseDto deletePluginConfigRoleBinding(@PathVariable("plugin-con
pluginConfigMgmtService.deletePluginConfigRoleBinding(pluginConfigId, pluginConfigRoleRequestDto);
return CommonResponseDto.okay();
}


@PostMapping("/plugins/configs/interfaces/param/metadata/query")
public CommonResponseDto queryPluginParamMetadata(
@RequestBody ParamMetadataQueryDto paramMetadataQueryDto) {
PluginConfigInterfaceParameterDto result = pluginConfigMgmtService.queryPluginParamMetadata(paramMetadataQueryDto);
return CommonResponseDto.okayWithData(result);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public CommonResponseDto proceedProcessInstance(@RequestBody ProceedProcInstRequ
*/
@RequestMapping(path = "/process/instances/tasknodes/{node-def-id}/session/{process-session-id}/tasknode-bindings", method = {
RequestMethod.POST, RequestMethod.PUT }, consumes = {
MediaType.APPLICATION_JSON_UTF8_VALUE }, produces = { MediaType.APPLICATION_JSON_UTF8_VALUE })
MediaType.APPLICATION_JSON_VALUE }, produces = { MediaType.APPLICATION_JSON_VALUE })
public CommonResponseDto updateProcessInstanceExecBindingsOfSession(
@PathVariable(name = "node-def-id") String nodeDefId,
@PathVariable(name = "process-session-id") String processSessionId,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.webank.wecube.platform.core.dto.plugin;

public class ParamMetadataQueryDto {

private String serviceId;
private String paramName;
public String getServiceId() {
return serviceId;
}
public void setServiceId(String serviceId) {
this.serviceId = serviceId;
}
public String getParamName() {
return paramName;
}
public void setParamName(String paramName) {
this.paramName = paramName;
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -14,6 +15,8 @@ public class DmeOutputParamAttr {
private Object retVal;
private boolean processed;
private List<EntityQueryExprNodeInfo> exprNodeInfos;
private EntityQueryExpr entityQueryExpr;

public PluginConfigInterfaces getInterf() {
return interf;
}
Expand Down Expand Up @@ -64,5 +67,12 @@ public boolean isRootEntityAttr(){

return false;
}
public EntityQueryExpr getEntityQueryExpr() {
return entityQueryExpr;
}
public void setEntityQueryExpr(EntityQueryExpr entityQueryExpr) {
this.entityQueryExpr = entityQueryExpr;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public List<EntityDto> getAllEntities(String dataModelExpression) {
log.info("Get all entities with expression:{}", dataModelExpression);
}

List<EntityQueryExprNodeInfo> exprNodeInfos = entityQueryExpressionParser.parse(dataModelExpression);
List<EntityQueryExprNodeInfo> exprNodeInfos = entityQueryExpressionParser.parse(dataModelExpression).getExprNodeInfos();
List<EntityDto> entityDtos = new ArrayList<EntityDto>();

for (EntityQueryExprNodeInfo exprNodeInfo : exprNodeInfos) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public List<Object> fetchDataWithFilter(DmeFilterDto dmeFilterDto) {
log.info("start to fetch data with filter:{}", dmeFilterDto);
}
List<EntityQueryExprNodeInfo> exprNodeInfos = entityQueryExpressionParser
.parse(dmeFilterDto.getDataModelExpression());
.parse(dmeFilterDto.getDataModelExpression()).getExprNodeInfos();

enrichEntityQueryExprNodeInfos(exprNodeInfos, dmeFilterDto);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public class EntityOperationContext {
protected EntityDataRouteFactory entityDataRouteFactory;

protected Map<Object, Object> externalCacheMap;

protected EntityQueryExpr entityQueryExpr;

public EntityQueryLinkNode getHeadEntityQueryLinkNode() {
return headEntityQueryLinkNode;
Expand Down Expand Up @@ -112,4 +114,12 @@ public void setExternalCacheMap(Map<Object, Object> externalCacheMap) {
this.externalCacheMap = externalCacheMap;
}

public EntityQueryExpr getEntityQueryExpr() {
return entityQueryExpr;
}

public void setEntityQueryExpr(EntityQueryExpr entityQueryExpr) {
this.entityQueryExpr = entityQueryExpr;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.webank.wecube.platform.core.service.dme;

import java.util.ArrayList;
import java.util.List;

public class EntityQueryExpr {

private List<EntityQueryExprNodeInfo> exprNodeInfos = new ArrayList<>();

private String exprOperation;

private String rawExpr;

public List<EntityQueryExprNodeInfo> getExprNodeInfos() {
return exprNodeInfos;
}

public void setExprNodeInfos(List<EntityQueryExprNodeInfo> exprNodeInfos) {
this.exprNodeInfos = exprNodeInfos;
}

public String getExprOperation() {
return exprOperation;
}

public void setExprOperation(String exprOperation) {
this.exprOperation = exprOperation;
}

public String getRawExpr() {
return rawExpr;
}

public void setRawExpr(String rawExpr) {
this.rawExpr = rawExpr;
}

public EntityQueryExpr addExprNode(EntityQueryExprNodeInfo exprNodeInfo) {
if(exprNodeInfo == null) {
return this;
}

exprNodeInfos.add(exprNodeInfo);

return this;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import com.webank.wecube.platform.core.utils.Constants;
/**
*
* @author gavin
Expand All @@ -16,13 +18,27 @@
public class EntityQueryExpressionParser {
public static final String PKG_DELIMITER = ":";
public static final String REG_ENTITY_ID = "@@\\w+@@";
public static final String DME_OPERATION_DELIMITER = Constants.DME_OPERATION_DELIMETER;
private Pattern entityIdPattern = Pattern.compile(REG_ENTITY_ID);

public List<EntityQueryExprNodeInfo> parse(String expr) {
public EntityQueryExpr parse(String rawExpr) {

if(StringUtils.isBlank(expr)) {
if(StringUtils.isBlank(rawExpr)) {
throw new IllegalArgumentException("Expression to parse cannot be blank.");
}

String[] rawExprParts = rawExpr.trim().split(DME_OPERATION_DELIMITER);

EntityQueryExpr entityQueryExpr = new EntityQueryExpr();
entityQueryExpr.setRawExpr(rawExpr);

String expr = null;
if(rawExprParts.length >= 2) {
expr = rawExprParts[0];
entityQueryExpr.setExprOperation(rawExprParts[1]);
}else {
expr = rawExpr;
}

String exprOpReg = String.format("[%s%s]", EntityLinkType.REF_TO.symbol(), EntityLinkType.REF_BY.symbol());

Expand Down Expand Up @@ -72,7 +88,9 @@ public List<EntityQueryExprNodeInfo> parse(String expr) {
parseEntityQueryNodeInfoDetails(singleNodeInfo, expr);
queryNodeInfos.add(singleNodeInfo);
}
return queryNodeInfos;

entityQueryExpr.setExprNodeInfos(queryNodeInfos);
return entityQueryExpr;
}

protected void parseEntityQueryNodeInfoDetails(EntityQueryExprNodeInfo nodeInfo, String entityQueryNodeExpr) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -83,15 +87,25 @@ public StandardEntityOperationResponseDto query(EntityRouteDescription entityDef

// POST List<Map<String, Object>>
public StandardEntityOperationResponseDto update(EntityRouteDescription entityDef,
List<EntityDataRecord> recordsToUpdate) {
List<EntityDataRecord> recordsToUpdate,Map<String,String> additionalRequestHeaders) {
URI requestUri = buildStandardOperationUri(entityDef, getUpdateUriTemplate());

List<Map<String, Object>> requestBody = convertToMapList(recordsToUpdate);

HttpHeaders headers = new HttpHeaders();
if(additionalRequestHeaders != null) {
for(String headerKey : additionalRequestHeaders.keySet()) {
headers.add(headerKey, additionalRequestHeaders.get(headerKey));
}
}

HttpEntity<List<Map<String, Object>>> 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<StandardEntityOperationResponseDto> 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());
Expand All @@ -100,14 +114,25 @@ public StandardEntityOperationResponseDto update(EntityRouteDescription entityDe
return result;
}

public StandardEntityOperationResponseDto updateData(EntityRouteDescription entityDef,List<Map<String, Object>> recordsToUpdate) {
public StandardEntityOperationResponseDto updateData(EntityRouteDescription entityDef,List<Map<String, Object>> recordsToUpdate, Map<String,String> 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<List<Map<String, Object>>> 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<StandardEntityOperationResponseDto> 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())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,11 @@ public List<StandardEntityDataNode> generatePreviewTree(EntityOperationRootCondi

protected EntityOperationContext buildEntityOperationContext(EntityOperationRootCondition condition,
RestTemplate restTemplate, Map<Object, Object> externalCacheMap) {
List<EntityQueryExprNodeInfo> exprNodeInfos = entityQueryExpressionParser.parse(condition.getEntityLinkExpr());
EntityQueryExpr entityQueryExpr = entityQueryExpressionParser.parse(condition.getEntityLinkExpr());
List<EntityQueryExprNodeInfo> exprNodeInfos = entityQueryExpr.getExprNodeInfos();

EntityOperationContext ctx = new EntityOperationContext();
ctx.setEntityQueryExpr(entityQueryExpr);
ctx.setEntityQueryExprNodeInfos(exprNodeInfos);
ctx.setOriginalEntityLinkExpression(condition.getEntityLinkExpr());
ctx.setOriginalEntityData(condition.getEntityIdentity());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -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<String,String> 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<EntityQueryExprNodeInfo> exprNodeInfos) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1003,7 +1003,7 @@ private void calculateInputParamValueFromObject(ExecutionJobs executionJob, Exec

String entityAttrName = null;
List<EntityQueryExprNodeInfo> currExprNodeInfos = this.entityQueryExpressionParser
.parse(parameter.getMappingEntityExpression());
.parse(parameter.getMappingEntityExpression()).getExprNodeInfos();
if (currExprNodeInfos == null || currExprNodeInfos.isEmpty()) {
// nothing
} else {
Expand Down
Loading

0 comments on commit 4f97028

Please sign in to comment.