summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvasraz <vasyl.razinkov@est.tech>2023-07-14 15:32:42 +0100
committerVasyl Razinkov <vasyl.razinkov@est.tech>2023-07-14 15:35:46 +0000
commit531f22dd3eebf6581d923f4d794ffcd4f5d8dbe2 (patch)
tree0ad0851af276e87fa12b4f830d89519011e3a885
parent97d78828e86277c27a6cd4d66c97e367dfc64538 (diff)
Fix 'Import service with JUEL-function produces wrong UI representation'
Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech> Change-Id: Icc37f2892fa5630df04d32e8496a57fc25ad7ad2 Issue-ID: SDC-4573
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java57
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java3
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/GroupInstanceOperation.java3
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperation.java3
4 files changed, 25 insertions, 41 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java
index e641365afa..d03a238fce 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java
@@ -55,6 +55,9 @@ import java.util.function.Function;
import java.util.stream.Collectors;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
+
+import lombok.AccessLevel;
+import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
@@ -674,7 +677,7 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
validateUserRole(user, service, new ArrayList<>(), AuditingActionEnum.CREATE_RESOURCE, null);
service.setCreatorUserId(user.getUserId());
// warn on overridden fields
- checkFieldsForOverideAttampt(service);
+ checkFieldsForOverideAttempt(service);
// enrich object
log.debug("enrich service with version and state");
service.setState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
@@ -689,7 +692,7 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
return createServiceByDao(service, user).left().bind(c -> updateCatalog(c, ChangeTypeEnum.LIFECYCLE).left().map(Service.class::cast));
}
- private void checkFieldsForOverideAttampt(Service service) {
+ private void checkFieldsForOverideAttempt(Service service) {
checkComponentFieldsForOverrideAttempt(service);
if (service.getDistributionStatus() != null) {
log.info("Distribution Status cannot be defined by user. This field will be overridden by the application");
@@ -2327,8 +2330,10 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
}
public boolean isServiceExist(String serviceName) {
- Either<Service, StorageOperationStatus> latestByName = toscaOperationFacade.getLatestByServiceName(serviceName);
- return latestByName.isLeft();
+ return toscaOperationFacade.getLatestByServiceName(serviceName).isLeft();
+ }
+
+ public void updateService(Service service, Map<String, Object> map) {
}
interface ArtifactGenerator<CallVal> extends Callable<Either<CallVal, ResponseFormat>> {
@@ -2336,26 +2341,16 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
}
@Getter
+ @AllArgsConstructor(access = AccessLevel.PRIVATE)
class HeatEnvArtifactGenerator implements ArtifactGenerator<ArtifactDefinition> {
private ArtifactDefinition artifactDefinition;
private Service service;
private String resourceInstanceName;
private User modifier;
- private String instanceId;
private boolean shouldLock;
private boolean inTransaction;
-
- HeatEnvArtifactGenerator(ArtifactDefinition artifactDefinition, Service service, String resourceInstanceName, User modifier,
- boolean shouldLock, boolean inTransaction, String instanceId) {
- this.artifactDefinition = artifactDefinition;
- this.service = service;
- this.resourceInstanceName = resourceInstanceName;
- this.modifier = modifier;
- this.shouldLock = shouldLock;
- this.instanceId = instanceId;
- this.inTransaction = inTransaction;
- }
+ private String instanceId;
@Override
public Either<ArtifactDefinition, ResponseFormat> call() throws Exception {
@@ -2365,23 +2360,14 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
}
}
+ @AllArgsConstructor(access = AccessLevel.PRIVATE)
class VfModuleArtifactGenerator implements ArtifactGenerator<ArtifactDefinition> {
- boolean shouldLock;
- boolean inTransaction;
private User user;
private ComponentInstance componentInstance;
private Service service;
-
- private VfModuleArtifactGenerator(User user, ComponentInstance componentInstance, Service service, boolean shouldLock,
- boolean inTransaction) {
- super();
- this.user = user;
- this.componentInstance = componentInstance;
- this.service = service;
- this.shouldLock = shouldLock;
- this.inTransaction = inTransaction;
- }
+ private boolean shouldLock;
+ private boolean inTransaction;
private Either<ArtifactDefinition, ResponseFormat> generateVfModuleInstanceArtifact(User modifier, ComponentInstance currVFInstance,
Service service, boolean shouldLock,
@@ -2400,13 +2386,11 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
vfModuleArtifact = fillVfModulePayload(modifier, currVFInstance, vfModuleArtifact, shouldLock, inTransaction, payloadWrapper,
responseWrapper, service);
}
- Either<ArtifactDefinition, ResponseFormat> result;
if (responseWrapper.isEmpty()) {
- result = Either.left(vfModuleArtifact);
+ return Either.left(vfModuleArtifact);
} else {
- result = Either.right(responseWrapper.getInnerElement());
+ return Either.right(responseWrapper.getInnerElement());
}
- return result;
}
private void fillVfModuleInstHeatEnvPayload(List<GroupInstance> groupsForCurrVF, Wrapper<String> payloadWrapper) {
@@ -2446,9 +2430,8 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
}
private List<GroupInstance> collectGroupsInstanceForCompInstance(ComponentInstance currVF) {
- Map<String, ArtifactDefinition> deploymentArtifacts = currVF.getDeploymentArtifacts();
if (currVF.getGroupInstances() != null) {
- currVF.getGroupInstances().forEach(gi -> gi.alignArtifactsUuid(deploymentArtifacts));
+ currVF.getGroupInstances().forEach(gi -> gi.alignArtifactsUuid(currVF.getDeploymentArtifacts()));
}
return currVF.getGroupInstances();
}
@@ -2471,14 +2454,12 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
vfModuleArtifactDefinition.setArtifactChecksum(newCheckSum);
Either<ArtifactDefinition, StorageOperationStatus> addArtifactToComponent = artifactToscaOperation
.addArtifactToComponent(vfModuleArtifactDefinition, service, NodeTypeEnum.ResourceInstance, true, currVF.getUniqueId());
- Either<ArtifactDefinition, ResponseFormat> result;
if (addArtifactToComponent.isLeft()) {
- result = Either.left(addArtifactToComponent.left().value());
+ return Either.left(addArtifactToComponent.left().value());
} else {
- result = Either
+ return Either
.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(addArtifactToComponent.right().value())));
}
- return result;
}
private ArtifactDefinition fillVfModulePayload(User modifier, ComponentInstance currVF, ArtifactDefinition vfModuleArtifact,
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java
index a15e39a478..3eca461970 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java
@@ -52,6 +52,7 @@ import lombok.Getter;
import lombok.Setter;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
+import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.json.simple.JSONObject;
@@ -1965,7 +1966,7 @@ public class ServiceImportBusinessLogic {
.forEach(instanceProperty -> {
toscaFunctionService.updateFunctionWithDataFromSelfComponent(instanceProperty.getToscaFunction(),
updatedService, instancePropertyMap, instanceAttributeMap);
- instanceProperty.setValue(instanceProperty.getToscaFunction().getValue());
+ instanceProperty.setValue(StringEscapeUtils.unescapeJava(instanceProperty.getToscaFunction().getValue()));
})
);
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/GroupInstanceOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/GroupInstanceOperation.java
index 67d9755808..eb25b30e89 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/GroupInstanceOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/GroupInstanceOperation.java
@@ -29,6 +29,7 @@ import java.util.UUID;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import org.apache.commons.collections.MapUtils;
+import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.janusgraph.core.JanusGraph;
@@ -405,7 +406,7 @@ public class GroupInstanceOperation extends AbstractOperation implements IGroupI
final GroupInstanceData groupInstanceData = findResInstanceRes.left().value();
//TODO fix
toscaFunctionValidator.validate(propDataDef, null);
- propertyValueData.setValue(propDataDef.getToscaFunction().getValue());
+ propertyValueData.setValue(StringEscapeUtils.unescapeJava(propDataDef.getToscaFunction().getValue()));
} else {
final String innerType = innerTypeEither.left().value();
Either<Object, Boolean> isValid = propertyOperation
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperation.java
index dbe11a8efd..b2c2fec33f 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperation.java
@@ -59,6 +59,7 @@ import java.util.regex.Pattern;
import java.util.stream.Collectors;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
+import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.tinkerpop.gremlin.structure.Edge;
@@ -1740,7 +1741,7 @@ public class PropertyOperation extends AbstractOperation implements IPropertyOpe
final Map<String, DataTypeDefinition> dataTypes) {
if (property.isToscaFunction()) {
toscaFunctionValidator.validate(property, containerComponent);
- property.setValue(property.getToscaFunction().getValue());
+ property.setValue(StringEscapeUtils.unescapeJava(property.getToscaFunction().getValue()));
return Either.left(property.getValue());
}
Either<String, JanusGraphOperationStatus> checkInnerType = checkInnerType(property);