}
final Component service = getServiceResult.left().value();
final Either<Component, StorageOperationStatus> getServiceDerivedFromTypeResult = toscaOperationFacade
- .getLatestByToscaResourceName(service.getDerivedFromGenericType());
+ .getLatestByToscaResourceName(service.getDerivedFromGenericType(), service.getModel());
if (getServiceDerivedFromTypeResult.isRight()) {
throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(getServiceResult.right().value()));
}
final Component service = getServiceResult.left().value();
final Either<Component, StorageOperationStatus> getServiceDerivedFromTypeResult = toscaOperationFacade
- .getLatestByToscaResourceName(service.getDerivedFromGenericType());
+ .getLatestByToscaResourceName(service.getDerivedFromGenericType(), service.getModel());
if (getServiceDerivedFromTypeResult.isRight()) {
throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(getServiceResult.right().value()));
}
}
}
- public Either<List<BaseType>, ActionStatus> getBaseTypes(final String categoryName, final String userId) {
+ public Either<List<BaseType>, ActionStatus> getBaseTypes(final String categoryName, final String userId, final String modelName) {
final ActionStatus status = validateUserExistsActionStatus(userId);
if (ActionStatus.OK != status) {
return Either.right(status);
}
- return Either.left(elementOperation.getBaseTypes(categoryName));
+ return Either.left(elementOperation.getBaseTypes(categoryName, modelName));
}
}
for (String member : groupType.getMembers()) {
// Verify that such Resource exist
Either<org.openecomp.sdc.be.model.Resource, StorageOperationStatus> eitherMemberExist = toscaOperationFacade
- .getLatestByToscaResourceName(member);
+ .getLatestByToscaResourceName(member, groupType.getModel());
if (eitherMemberExist.isRight()) {
StorageOperationStatus operationStatus = eitherMemberExist.right().value();
log.debug("Error when fetching parent resource {}, error: {}", member, operationStatus);
}
if (result.isLeft()) {
for (String targetId : policyType.getTargets()) {
- boolean isValid = toscaOperationFacade.getLatestByToscaResourceName(targetId).isLeft();
+ boolean isValid = toscaOperationFacade.getLatestByToscaResourceName(targetId, policyType.getModel()).isLeft();
if (!isValid) { // check if it is a groupType
final Either<GroupTypeDefinition, StorageOperationStatus> groupTypeFound = groupTypeOperation
.getLatestGroupTypeByType(targetId, policyType.getModel(), false);
componentsUtils.auditResource(responseFormat, csarInfo.getModifier(), resource, AuditingActionEnum.CREATE_RESOURCE);
throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(status), csarInfo.getCsarUUID());
} else if (StringUtils.isNotEmpty(currVfcToscaName)) {
- return (Resource) toscaOperationFacade.getLatestByToscaResourceName(currVfcToscaName).left()
+ return (Resource) toscaOperationFacade.getLatestByToscaResourceName(currVfcToscaName, resource.getModel()).left()
.on(st -> findVfcResource(csarInfo, resource, previousVfcToscaName, null, st));
}
return null;
String nodeName, String substitutableAsNodeType) {
try {
for (Entry<String, NodeTypeInfo> nodeTypeEntry : nodeTypesInfo.entrySet()) {
- if (nodeTypeEntry.getValue().isNested() && !nodeTypeAlreadyExists(nodeTypeEntry.getKey())) {
+ if (nodeTypeEntry.getValue().isNested() && !nodeTypeAlreadyExists(nodeTypeEntry.getKey(), resource.getModel())) {
handleNestedVfc(resource, nodeTypesArtifactsToHandle, nodeTypesNewCreatedArtifacts, nodeTypesInfo, csarInfo,
nodeTypeEntry.getKey());
log.trace("************* finished to create node {}", nodeTypeEntry.getKey());
}
}
- private boolean nodeTypeAlreadyExists(final String toscaResourceName) {
- return toscaOperationFacade.getLatestByToscaResourceName(toscaResourceName).isLeft();
+ private boolean nodeTypeAlreadyExists(final String toscaResourceName, String modelName) {
+ return toscaOperationFacade.getLatestByToscaResourceName(toscaResourceName, modelName).isLeft();
}
private Either<Resource, ResponseFormat> handleVfCsarArtifacts(Resource resource, CsarInfo csarInfo, List<ArtifactDefinition> createdArtifacts,
final CsarInfo csarInfo, final boolean isNested,
final String nodeName) {
final Either<Component, StorageOperationStatus> latestByToscaName = toscaOperationFacade.getLatestByToscaResourceName(
- buildNestedToscaResourceName(resource.getResourceType().name(), csarInfo.getVfResourceName(), nodeName).getRight());
+ buildNestedToscaResourceName(resource.getResourceType().name(), csarInfo.getVfResourceName(), nodeName).getRight(), resource.getModel());
if (latestByToscaName.isLeft()) {
final Resource nestedResource = (Resource) latestByToscaName.left().value();
log.debug(VALIDATE_DERIVED_BEFORE_UPDATE);
private Component getParentComponent(Resource newResource) {
String toscaResourceNameDerivedFrom = newResource.getDerivedFrom().get(0);
Either<Component, StorageOperationStatus> latestByToscaResourceName = toscaOperationFacade
- .getLatestByToscaResourceName(toscaResourceNameDerivedFrom);
+ .getLatestByToscaResourceName(toscaResourceNameDerivedFrom, newResource.getModel());
if (latestByToscaResourceName.isRight()) {
BeEcompErrorManager.getInstance()
.logInternalDataError("mergeOldResourceMetadataWithNew", "derived from resource not found", ErrorSeverity.ERROR);
String currentTemplateName = currentResource.getDerivedFrom().get(0);
String updatedTemplateName = updateInfoResource.getDerivedFrom().get(0);
Either<Boolean, StorageOperationStatus> dataModelResponse = toscaOperationFacade
- .validateToscaResourceNameExtends(currentTemplateName, updatedTemplateName);
+ .validateToscaResourceNameExtends(currentTemplateName, updatedTemplateName, currentResource.getModel());
if (dataModelResponse.isRight()) {
StorageOperationStatus storageStatus = dataModelResponse.right().value();
BeEcompErrorManager.getInstance().logBeDaoSystemError("Create/Update Resource - validateDerivingFromExtendingType");
log.debug("validate resource properties default values");
List<PropertyDefinition> properties = resource.getProperties();
if (properties != null) {
- iterateOverProperties(properties);
+ iterateOverProperties(properties, resource.getModel());
}
return true;
}
- public void iterateOverProperties(List<PropertyDefinition> properties) {
+ public void iterateOverProperties(List<PropertyDefinition> properties, String model) {
String type = null;
String innerType = null;
for (PropertyDefinition property : properties) {
- if (!propertyOperation.isPropertyTypeValid(property, null)) {
+ if (!propertyOperation.isPropertyTypeValid(property, model)) {
log.info("Invalid type for property {}", property);
throw new ByActionStatusComponentException(ActionStatus.INVALID_PROPERTY_TYPE, property.getType(), property.getName());
}
- Map<String, DataTypeDefinition> allDataTypes = componentsUtils.getAllDataTypes(applicationDataTypeCache, property.getModel());
+ Map<String, DataTypeDefinition> allDataTypes = componentsUtils.getAllDataTypes(applicationDataTypeCache, model);
type = property.getType();
if (type.equals(ToscaPropertyType.LIST.getType()) || type.equals(ToscaPropertyType.MAP.getType())) {
ResponseFormat responseFormat = validateMapOrListPropertyType(property, innerType, allDataTypes);
}
final Either<Resource, StorageOperationStatus> resourceEither =
toscaOperationFacade.getComponentByNameAndVendorRelease(resource.getComponentType(), resource.getName(),
- resource.getVendorRelease(), JsonParseFlagEnum.ParseAll);
+ resource.getVendorRelease(), JsonParseFlagEnum.ParseAll, resource.getModel());
if (resourceEither.isLeft() && toscaOperationFacade.isNodeAssociatedToModel(resource.getModel(), resource)) {
if (resource.getModel() == null) {
throw new ByActionStatusComponentException(ActionStatus.COMPONENT_WITH_VENDOR_RELEASE_ALREADY_EXISTS,
String derivedFrom = toscaDerivedFromElement.left().value();
log.debug("Derived from TOSCA name is {}", derivedFrom);
resource.setDerivedFrom(Arrays.asList(new String[]{derivedFrom}));
- Either<Resource, StorageOperationStatus> latestByToscaResourceName = toscaOperationFacade.getLatestByToscaResourceName(derivedFrom);
+ Either<Resource, StorageOperationStatus> latestByToscaResourceName = toscaOperationFacade.getLatestByToscaResourceName(derivedFrom, resource.getModel());
if (latestByToscaResourceName.isRight()) {
StorageOperationStatus operationStatus = latestByToscaResourceName.right().value();
if (operationStatus == StorageOperationStatus.NOT_FOUND) {
log.debug("Error occured during fetching node type with tosca name {}, error: {}", currVfcToscaName, status);
throw new ComponentException(componentsUtils.convertFromStorageResponse(status), csarInfo.getCsarUUID());
} else if (org.apache.commons.lang.StringUtils.isNotEmpty(currVfcToscaName)) {
- return (Resource) toscaOperationFacade.getLatestByToscaResourceName(currVfcToscaName).left()
+ return (Resource) toscaOperationFacade.getLatestByToscaResourceName(currVfcToscaName, resource.getModel()).left()
.on(st -> findVfcResource(csarInfo, resource, previousVfcToscaName, null, st));
}
return null;
String currentTemplateName = currentResource.getDerivedFrom().get(0);
String updatedTemplateName = updateInfoResource.getDerivedFrom().get(0);
Either<Boolean, StorageOperationStatus> dataModelResponse = toscaOperationFacade
- .validateToscaResourceNameExtends(currentTemplateName, updatedTemplateName);
+ .validateToscaResourceNameExtends(currentTemplateName, updatedTemplateName, currentResource.getModel());
if (dataModelResponse.isRight()) {
StorageOperationStatus storageStatus = dataModelResponse.right().value();
BeEcompErrorManager.getInstance().logBeDaoSystemError("Create/Update Resource - validateDerivingFromExtendingType");
return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERIC_TYPE_NOT_FOUND, component.assetType(), genericTypeToscaName));
}
} else {
- genericType = toscaOperationFacade.getByToscaResourceNameAndVersion(genericTypeToscaName, component.getDerivedFromGenericVersion());
+ genericType = toscaOperationFacade.getByToscaResourceNameAndVersion(genericTypeToscaName, component.getDerivedFromGenericVersion(), component.getModel());
}
Resource genericTypeResource = genericType.left().value();
@PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
public Response getCategoryBaseTypes(@PathParam(value = "categoryName") final String categoryName,
@PathParam(value = "componentType") final String componentType, @Context final HttpServletRequest request,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
-
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
+ @Parameter(description = "model", required = false) @QueryParam("model") String modelName) {
try {
final ElementBusinessLogic elementBL = getElementBL(request.getSession().getServletContext());
- final Either<List<BaseType>, ActionStatus> either = elementBL.getBaseTypes(categoryName, userId);
+ final Either<List<BaseType>, ActionStatus> either = elementBL.getBaseTypes(categoryName, userId, modelName);
if (either.isRight() || either.left().value() == null) {
log.debug("No base types were found");
if (component.getDerivedFromGenericType() != null && !component.getDerivedFromGenericType()
.startsWith("org.openecomp.resource.abstract.nodes.")) {
final Either<Component, StorageOperationStatus> baseType = toscaOperationFacade
- .getByToscaResourceNameAndVersion(component.getDerivedFromGenericType(), component.getDerivedFromGenericVersion());
+ .getByToscaResourceNameAndVersion(component.getDerivedFromGenericType(), component.getDerivedFromGenericVersion(), component.getModel());
if (baseType.isLeft() && baseType.left().value() != null) {
addDependencies(imports, dependencies, baseType.left().value());
} else {
}
@Override
- public List<BaseType> getBaseTypes(String categoryName) {
+ public List<BaseType> getBaseTypes(String categoryName, String modelName) {
// TODO Auto-generated method stub
return null;
}
public static void beforeClass() {
importManager = new ResourceImportManager(componentsUtils, capabilityTypeOperation, interfaceDefinitionHandler);
importManager.setAuditingManager(auditingManager);
- when(toscaOperationFacade.getLatestByToscaResourceName(Mockito.anyString())).thenReturn(Either.left(null));
+ when(toscaOperationFacade.getLatestByToscaResourceName(Mockito.anyString(), Mockito.any())).thenReturn(Either.left(null));
when(toscaOperationFacade.getLatestByToscaResourceNameAndModel(Mockito.anyString(), Mockito.any())).thenReturn(Either.left(null));
importManager.setResponseFormatManager(responseFormatManager);
importManager.setResourceBusinessLogic(resourceBusinessLogic);
Mockito.reset(auditingManager, responseFormatManager, resourceBusinessLogic, userAdmin);
Either<Component, StorageOperationStatus> notFound = Either.right(StorageOperationStatus.NOT_FOUND);
when(toscaOperationFacade.getComponentByNameAndVendorRelease(any(ComponentTypeEnum.class), anyString(), anyString(),
- any(JsonParseFlagEnum.class))).thenReturn(notFound);
+ any(JsonParseFlagEnum.class), any())).thenReturn(notFound);
}
@Test
setResourceBusinessLogicMock();
final Either<Component, StorageOperationStatus> foundResourceEither = Either.left(Mockito.mock(Resource.class));
when(toscaOperationFacade.getComponentByNameAndVendorRelease(any(ComponentTypeEnum.class), anyString(), anyString(),
- any(JsonParseFlagEnum.class))).thenReturn(foundResourceEither);
+ any(JsonParseFlagEnum.class), any())).thenReturn(foundResourceEither);
when(toscaOperationFacade.isNodeAssociatedToModel(eq(null), any(Resource.class))).thenReturn(true);
String jsonContent = ImportUtilsTest.loadFileNameToJsonString("normative-types-new-blockStorage.yml");
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anySet;
import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
.thenReturn(Either.left(service));
when(toscaOperationFacade.getToscaFullElement(eq(ORIGIN_COMPONENT_ID)))
.thenReturn(Either.left(originService));
- when(toscaOperationFacade.getLatestByToscaResourceName(eq(originService.getDerivedFromGenericType())))
+ when(toscaOperationFacade.getLatestByToscaResourceName(eq(originService.getDerivedFromGenericType()), isNull()))
.thenReturn(Either.left(serviceBaseComponent));
when(toscaOperationFacade.getToscaElement(eq(ORIGIN_COMPONENT_ID), any(ComponentParametersView.class)))
.thenReturn(Either.left(originService));
List<BaseType> baseTypes = new ArrayList<>();
baseTypes.add(new BaseType("org.openecomp.type"));
String categoryName = "CAT01";
+ String modelName = "MODEL01";
when(userValidations.validateUserExistsActionStatus(eq(user.getUserId()))).thenReturn(ActionStatus.OK);
- when(elementDao.getBaseTypes(categoryName)).thenReturn(baseTypes);
- Assert.assertTrue(elementBusinessLogic.getBaseTypes(categoryName, user.getUserId())
+ when(elementDao.getBaseTypes(categoryName, modelName)).thenReturn(baseTypes);
+ Assert.assertTrue(elementBusinessLogic.getBaseTypes(categoryName, user.getUserId(), modelName)
.isLeft());
}
@Test
public void testGetBaseTypes_givenUserValidationFails_thenReturnsException() {
when(userValidations.validateUserExistsActionStatus(eq(user.getUserId()))).thenReturn(ActionStatus.RESTRICTED_OPERATION);
- Assert.assertTrue(elementBusinessLogic.getBaseTypes("CAT01", user.getUserId()).isRight());
+ Assert.assertTrue(elementBusinessLogic.getBaseTypes("CAT01", user.getUserId(), null).isRight());
}
}
\ No newline at end of file
YamlTemplateParsingHandler yamlTemplateParser = new YamlTemplateParsingHandler(mockJanusGraphDao, null, Mockito.mock(AnnotationBusinessLogic.class), null);
final ParsedToscaYamlInfo parsedToscaYamlInfo = yamlTemplateParser.parseResourceInfoFromYAML("Definitions/my_vnf.yml", resourceYml, Collections.EMPTY_MAP, Collections.EMPTY_MAP, "myVnf", resourceResponse);
- when(toscaOperationFacade.getLatestByToscaResourceName(anyString())).thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
+ when(toscaOperationFacade.getLatestByToscaResourceName(anyString(), any())).thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
Resource vduCp = new Resource();
vduCp.setToscaResourceName("tosca.nodes.nfv.VduCp");
vduCp.setState(LifecycleStateEnum.CERTIFIED);
when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
Either<Boolean, StorageOperationStatus> isToscaNameExtending = Either.left(true);
- when(toscaOperationFacade.validateToscaResourceNameExtends(anyString(), anyString()))
+ when(toscaOperationFacade.validateToscaResourceNameExtends(anyString(), anyString(), anyString()))
.thenReturn(isToscaNameExtending);
Either<Map<String, PropertyDefinition>, StorageOperationStatus> findPropertiesOfNode = Either
when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
Either<Boolean, StorageOperationStatus> isToscaNameExtending = Either.left(false);
- when(toscaOperationFacade.validateToscaResourceNameExtends(anyString(), anyString()))
+ when(toscaOperationFacade.validateToscaResourceNameExtends(anyString(), anyString(), anyString()))
.thenReturn(isToscaNameExtending);
resource.setVersion("1.0");
assertThat(createdResource).isNotNull();
Either<Resource, StorageOperationStatus> getLatestResult = Either.left(createdResource);
Either<Component, StorageOperationStatus> getCompLatestResult = Either.left(createdResource);
- when(toscaOperationFacade.getLatestByToscaResourceName(resourceExist.getToscaResourceName()))
+ when(toscaOperationFacade.getLatestByToscaResourceName(resourceExist.getToscaResourceName(), null))
.thenReturn(getCompLatestResult);
when(toscaOperationFacade.getLatestByToscaResourceNameAndModel(resourceExist.getToscaResourceName(), null))
.thenReturn(getCompLatestResult);
.getRight();
when(toscaOperationFacade.getLatestByName(resourceToUpdate.getName(), null))
.thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
- when(toscaOperationFacade.getLatestByToscaResourceName(resourceToUpdate.getToscaResourceName()))
+ when(toscaOperationFacade.getLatestByToscaResourceName(resourceToUpdate.getToscaResourceName(), null))
.thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
- when(toscaOperationFacade.getLatestByToscaResourceName(nestedResourceName))
+ when(toscaOperationFacade.getLatestByToscaResourceName(nestedResourceName, null))
.thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
when(toscaOperationFacade.getLatestByToscaResourceNameAndModel(resourceToUpdate.getToscaResourceName(), null))
.getRight();
when(toscaOperationFacade.getLatestByName(resourceToUpdate.getName(), null))
.thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
- when(toscaOperationFacade.getLatestByToscaResourceName(resourceToUpdate.getToscaResourceName()))
+ when(toscaOperationFacade.getLatestByToscaResourceName(resourceToUpdate.getToscaResourceName(), null))
.thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
when(toscaOperationFacade.getLatestByToscaResourceNameAndModel(resourceToUpdate.getToscaResourceName(), null))
.thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
- when(toscaOperationFacade.getLatestByToscaResourceName(nestedResourceName))
+ when(toscaOperationFacade.getLatestByToscaResourceName(nestedResourceName, null))
.thenReturn(Either.left(resourceResponse));
when(toscaOperationFacade.overrideComponent(any(Resource.class), any(Resource.class)))
.thenReturn(Either.left(resourceResponse));
private Resource createRoot() {
rootType = setupGenericTypeMock(GENERIC_ROOT_NAME);
- when(toscaOperationFacade.getLatestByToscaResourceName(GENERIC_ROOT_NAME))
+ when(toscaOperationFacade.getLatestByToscaResourceName(GENERIC_ROOT_NAME, null))
.thenReturn(Either.left(rootType));
return rootType;
}
final Service service = createServiceObject(false);
Resource resource = new Resource();
Either<Component, StorageOperationStatus> getCompLatestResult = Either.left(resource);
- when(toscaOperationFacade.getLatestByToscaResourceName(anyString()))
+ when(toscaOperationFacade.getLatestByToscaResourceName(anyString(), any()))
.thenReturn(getCompLatestResult);
final CsarInfo csarInfo = getCsarInfo();
final Service service = createServiceObject(false);
Resource resource = new Resource();
Either<Component, StorageOperationStatus> getCompLatestResult = Either.left(resource);
- when(toscaOperationFacade.getLatestByToscaResourceName(anyString()))
+ when(toscaOperationFacade.getLatestByToscaResourceName(anyString(), any()))
.thenReturn(getCompLatestResult);
Assertions.assertNotNull(extractedVfcsArtifacts);
testSubject.findAddNodeTypeArtifactsToHandle(getCsarInfo(), nodeTypesArtifactsToHandle, service,
updatedDerivedFromList.add("23344567778");
updateInfoResource.setDerivedFrom(updatedDerivedFromList);
- when(toscaOperationFacade.validateToscaResourceNameExtends(anyString(), anyString()))
+ when(toscaOperationFacade.validateToscaResourceNameExtends(anyString(), anyString(), any()))
.thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
Assertions.assertNotNull(
Resource currentResource = createParseResourceObject(true);
Resource updateInfoResource = createParseResourceObject(true);
- when(toscaOperationFacade.validateToscaResourceNameExtends(anyString(), anyString()))
+ when(toscaOperationFacade.validateToscaResourceNameExtends(anyString(), anyString(), any()))
.thenReturn(Either.left(false));
Assertions.assertNotNull(
}
@Override
- public <T extends Component> Either<T, StorageOperationStatus> getLatestByToscaResourceName(String toscaResourceName) {
+ public <T extends Component> Either<T, StorageOperationStatus> getLatestByToscaResourceName(String toscaResourceName, String model) {
if(toscaResourceName.equals(ForwardingPathUtils.FORWARDING_PATH_NODE_NAME) || toscaResourceName.equals(ForwardingPathUtils.FORWARDER_CAPABILITY)){
Resource component = new Resource();
component.setToscaResourceName(GENERIC_SERVICE_NAME);
return Either.left((T)component);
}
- return super.getLatestByToscaResourceName(toscaResourceName);
+ return super.getLatestByToscaResourceName(toscaResourceName, model);
}
}
void getBaseTypesTest() {
String path = "/v1/category/services/CAT1/baseTypes";
Either<List<BaseType>, ActionStatus> baseTypesEither = Either.left(new ArrayList<>());
- when(elementBusinessLogic.getBaseTypes("CAT1", designerUser.getUserId()))
+ when(elementBusinessLogic.getBaseTypes("CAT1", designerUser.getUserId(), null))
.thenReturn(baseTypesEither);
Response response = target()
String path = "/v1/category/services/CAT1/baseTypes";
Either<List<BaseType>, ActionStatus> baseTypesEither = Either.right(ActionStatus.NO_CONTENT);
- when(elementBusinessLogic.getBaseTypes("CAT1", designerUser.getUserId()))
+ when(elementBusinessLogic.getBaseTypes("CAT1", designerUser.getUserId(), null))
.thenReturn(baseTypesEither);
Response response = target()
component.setDerivedFromGenericType("org.typeA");
component.setDerivedFromGenericVersion("1.0");
- when(toscaOperationFacade.getByToscaResourceNameAndVersion("org.typeA", "1.0")).thenReturn(Either.left(baseType));
+ when(toscaOperationFacade.getByToscaResourceNameAndVersion("org.typeA", "1.0", null)).thenReturn(Either.left(baseType));
// default test
result = Deencapsulation.invoke(testSubject, "fillImports", component, toscaTemplate);
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+import java.util.stream.StreamSupport;
import java.util.Optional;
import org.apache.commons.collections.MapUtils;
+import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.tinkerpop.gremlin.structure.Direction;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
import org.openecomp.sdc.be.dao.jsongraph.utils.JsonParserUtils;
+import org.openecomp.sdc.be.dao.neo4j.GraphEdgeLabels;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
public Either<List<GraphVertex>, JanusGraphOperationStatus> getByCriteria(VertexTypeEnum type, Map<GraphPropertyEnum, Object> props,
Map<GraphPropertyEnum, Object> hasNotProps,
- JsonParseFlagEnum parseFlag) {
- return getByCriteria(type, props, hasNotProps, null, parseFlag);
+ JsonParseFlagEnum parseFlag,
+ String model) {
+ return getByCriteria(type, props, hasNotProps, null, parseFlag, model);
}
public Either<List<GraphVertex>, JanusGraphOperationStatus> getByCriteria(final VertexTypeEnum type,
final Map<GraphPropertyEnum, Object> hasProps,
final Map<GraphPropertyEnum, Object> hasNotProps,
final Map<String, Entry<JanusGraphPredicate, Object>> predicates,
- final JsonParseFlagEnum parseFlag) {
+ final JsonParseFlagEnum parseFlag,
+ final String model) {
Either<JanusGraph, JanusGraphOperationStatus> graph = janusGraphClient.getGraph();
if (graph.isLeft()) {
try {
JanusGraph tGraph = graph.left().value();
JanusGraphQuery<? extends JanusGraphQuery> query = tGraph.query();
+
if (type != null) {
query = query.has(GraphPropertyEnum.LABEL.getProperty(), type.getName());
}
return Either.right(JanusGraphOperationStatus.NOT_FOUND);
}
List<GraphVertex> result = new ArrayList<>();
- vertices.forEach(vertex -> result.add(createAndFill(vertex, parseFlag)));
+
+ final Predicate<? super JanusGraphVertex> filterPredicate = StringUtils.isEmpty(model) ? this::vertexNotConnectedToAnyModel : vertex -> vertexValidForModel(vertex, model);
+ final List<JanusGraphVertex> verticesForModel = StreamSupport.stream(vertices.spliterator(), false).filter(filterPredicate).collect(Collectors.toList());
+ if (verticesForModel == null || verticesForModel.size() == 0) {
+ return Either.right(JanusGraphOperationStatus.NOT_FOUND);
+ }
+
+ verticesForModel.forEach(vertex -> result.add(createAndFill(vertex, parseFlag)));
if (logger.isDebugEnabled()) {
logger.debug("Number of fetched nodes in graph for criteria : from type '{}' and properties '{}' is '{}'", type, hasProps,
result.size());
return Either.right(graph.right().value());
}
}
+
+ public Either<List<GraphVertex>, JanusGraphOperationStatus> getByCriteria(VertexTypeEnum type,
+ Map<GraphPropertyEnum, Object> props, Map<GraphPropertyEnum, Object> hasNotProps,
+ JsonParseFlagEnum parseFlag) {
+ return getByCriteria(type, props, hasNotProps, null, parseFlag);
+ }
+
+ public Either<List<GraphVertex>, JanusGraphOperationStatus> getByCriteria(final VertexTypeEnum type,
+ final Map<GraphPropertyEnum, Object> hasProps, final Map<GraphPropertyEnum, Object> hasNotProps,
+ final Map<String, Entry<JanusGraphPredicate, Object>> predicates, final JsonParseFlagEnum parseFlag) {
+ Either<JanusGraph, JanusGraphOperationStatus> graph = janusGraphClient.getGraph();
+ if (graph.isLeft()) {
+ try {
+ JanusGraph tGraph = graph.left().value();
+ JanusGraphQuery<? extends JanusGraphQuery> query = tGraph.query();
+
+ if (type != null) {
+ query = query.has(GraphPropertyEnum.LABEL.getProperty(), type.getName());
+ }
+ if (hasProps != null && !hasProps.isEmpty()) {
+ for (Map.Entry<GraphPropertyEnum, Object> entry : hasProps.entrySet()) {
+ query = query.has(entry.getKey().getProperty(), entry.getValue());
+ }
+ }
+ if (hasNotProps != null && !hasNotProps.isEmpty()) {
+ for (Map.Entry<GraphPropertyEnum, Object> entry : hasNotProps.entrySet()) {
+ if (entry.getValue() instanceof List) {
+ buildMultipleNegateQueryFromList(entry, query);
+ } else {
+ query = query.hasNot(entry.getKey().getProperty(), entry.getValue());
+ }
+ }
+ }
+ if (predicates != null && !predicates.isEmpty()) {
+ for (Map.Entry<String, Entry<JanusGraphPredicate, Object>> entry : predicates.entrySet()) {
+ JanusGraphPredicate predicate = entry.getValue().getKey();
+ Object object = entry.getValue().getValue();
+ query = query.has(entry.getKey(), predicate, object);
+ }
+ }
+ Iterable<JanusGraphVertex> vertices = query.vertices();
+ if (vertices == null || !vertices.iterator().hasNext()) {
+ return Either.right(JanusGraphOperationStatus.NOT_FOUND);
+ }
+ List<GraphVertex> result = new ArrayList<>();
+
+ vertices.forEach(vertex -> result.add(createAndFill(vertex, parseFlag)));
+ if (logger.isDebugEnabled()) {
+ logger.debug(
+ "Number of fetched nodes in graph for criteria : from type '{}' and properties '{}' is '{}'",
+ type, hasProps, result.size());
+ }
+ return Either.left(result);
+ } catch (Exception e) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Failed to get by criteria for type '{}' and properties '{}'", type, hasProps, e);
+ }
+ return Either.right(JanusGraphClient.handleJanusGraphException(e));
+ }
+ } else {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Failed to get by criteria for type '{}' and properties '{}'. Error : '{}'", type,
+ hasProps, graph.right().value());
+ }
+ return Either.right(graph.right().value());
+ }
+ }
+
+ private boolean vertexValidForModel(final JanusGraphVertex vertex, final String model) {
+ final Either<List<ImmutablePair<JanusGraphVertex, Edge>>, JanusGraphOperationStatus> modelVertices = getParentVerticies(vertex, GraphEdgeLabels.MODEL_ELEMENT);
+
+ if (modelVertices.isLeft()) {
+ for (ImmutablePair<JanusGraphVertex, Edge> vertexPair : modelVertices.left().value()) {
+ if (model.equals((String)vertexPair.getLeft().property("name").value())) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ private Either<List<ImmutablePair<JanusGraphVertex, Edge>>, JanusGraphOperationStatus> getParentVerticies(
+ final JanusGraphVertex rootVertex, final GraphEdgeLabels edgeType) {
+ return getEdgeVerticies(rootVertex, Direction.IN, edgeType);
+ }
+
+ private Either<List<ImmutablePair<JanusGraphVertex, Edge>>, JanusGraphOperationStatus> getEdgeVerticies(
+ final JanusGraphVertex rootVertex, final Direction direction, final GraphEdgeLabels edgeType) {
+ final List<ImmutablePair<JanusGraphVertex, Edge>> immutablePairs = new ArrayList<>();
+ final Iterator<Edge> edgesCreatorIterator = rootVertex.edges(direction, edgeType.getProperty());
+ if (edgesCreatorIterator != null) {
+ while (edgesCreatorIterator.hasNext()) {
+ Edge edge = edgesCreatorIterator.next();
+ JanusGraphVertex vertex = Direction.OUT.equals(direction)? (JanusGraphVertex) edge.inVertex() : (JanusGraphVertex) edge.outVertex();
+ ImmutablePair<JanusGraphVertex, Edge> immutablePair = new ImmutablePair<>(vertex, edge);
+ immutablePairs.add(immutablePair);
+ }
+ }
+ if (immutablePairs.isEmpty()) {
+ return Either.right(JanusGraphOperationStatus.NOT_FOUND);
+ }
+ return Either.left(immutablePairs);
+ }
+
+ private boolean vertexNotConnectedToAnyModel(final JanusGraphVertex vertex) {
+ String vt = (String)vertex.property(GraphPropertyEnum.LABEL.getProperty()).value();
+ VertexTypeEnum vertexType = VertexTypeEnum.getByName(vt);
+ EdgeLabelEnum edgeLabel = vertexType.equals(VertexTypeEnum.TOPOLOGY_TEMPLATE) ? EdgeLabelEnum.MODEL : EdgeLabelEnum.MODEL_ELEMENT;
+ return !vertex.edges(Direction.IN, edgeLabel.name()).hasNext();
+ }
public Either<Iterator<Vertex>, JanusGraphOperationStatus> getCatalogOrArchiveVerticies(boolean isCatalog) {
Either<JanusGraph, JanusGraphOperationStatus> graph = janusGraphClient.getGraph();
Map<GraphPropertyEnum, Object> propsHasNot = new HashMap<>();
propsHasNot.put(GraphPropertyEnum.IS_DELETED, true);
Either<List<GraphVertex>, JanusGraphOperationStatus> byCriteria = janusGraphDao
- .getByCriteria(VertexTypeEnum.NODE_TYPE, props, propsHasNot, JsonParseFlagEnum.NoParse);
+ .getByCriteria(VertexTypeEnum.NODE_TYPE, props, propsHasNot, JsonParseFlagEnum.NoParse, nodeType.getModel());
if (byCriteria.isRight()) {
log.debug("Failed to fetch derived by props {} error {}", props, byCriteria.right().value());
return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(byCriteria.right().value()));
final Map<GraphPropertyEnum, Object> propertiesNotToMatch = new EnumMap<>(GraphPropertyEnum.class);
propertiesToMatch.put(GraphPropertyEnum.TOSCA_RESOURCE_NAME, nodeName);
propertiesToMatch.put(GraphPropertyEnum.IS_HIGHEST_VERSION, true);
- propertiesToMatch.put(GraphPropertyEnum.MODEL, model);
propertiesNotToMatch.put(GraphPropertyEnum.IS_DELETED, true);
final Either<List<GraphVertex>, JanusGraphOperationStatus> highestResources = janusGraphDao
- .getByCriteria(null, propertiesToMatch, propertiesNotToMatch, parseFlag);
+ .getByCriteria(null, propertiesToMatch, propertiesNotToMatch, parseFlag, model);
if (highestResources.isRight()) {
final JanusGraphOperationStatus status = highestResources.right().value();
log.debug("failed to find resource with name {}. status={} ", nodeName, status);
return getToscaElementByOperation(highestResource, filter);
}
- public <T extends Component> Either<T, StorageOperationStatus> getLatestByToscaResourceName(String toscaResourceName) {
- return getLatestByName(GraphPropertyEnum.TOSCA_RESOURCE_NAME, toscaResourceName, null);
+ public <T extends Component> Either<T, StorageOperationStatus> getLatestByToscaResourceName(String toscaResourceName, String modelName) {
+ return getLatestByName(GraphPropertyEnum.TOSCA_RESOURCE_NAME, toscaResourceName, modelName);
}
public <T extends Component> Either<T, StorageOperationStatus> getFullLatestComponentByToscaResourceName(String toscaResourceName) {
props.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name());
Map<String, Entry<JanusGraphPredicate, Object>> predicateCriteria = getVendorVersionPredicate(vendorRelease);
Either<List<GraphVertex>, JanusGraphOperationStatus> getLatestRes = janusGraphDao
- .getByCriteria(vertexType, props, null, predicateCriteria, parseFlag);
+ .getByCriteria(vertexType, props, null, predicateCriteria, parseFlag, null);
if (getLatestRes.isRight() || CollectionUtils.isEmpty(getLatestRes.left().value())) {
getLatestRes = janusGraphDao.getByCriteria(vertexType, props, parseFlag);
}
});
}
- public <T extends Component> Either<T, StorageOperationStatus> getByToscaResourceNameAndVersion(final String toscaResourceName, final String version) {
+ public <T extends Component> Either<T, StorageOperationStatus> getByToscaResourceNameAndVersion(final String toscaResourceName, final String version, final String model) {
Either<T, StorageOperationStatus> result;
Map<GraphPropertyEnum, Object> hasProperties = new EnumMap<>(GraphPropertyEnum.class);
hasNotProperties.put(GraphPropertyEnum.IS_DELETED, true);
Either<List<GraphVertex>, JanusGraphOperationStatus> getResourceRes = janusGraphDao
- .getByCriteria(VertexTypeEnum.NODE_TYPE, hasProperties, hasNotProperties, JsonParseFlagEnum.ParseAll);
+ .getByCriteria(VertexTypeEnum.NODE_TYPE, hasProperties, hasNotProperties, JsonParseFlagEnum.ParseAll, model);
if (getResourceRes.isRight()) {
JanusGraphOperationStatus status = getResourceRes.right().value();
log.debug("failed to find resource with toscaResourceName {}, version {}. Status is {} ", toscaResourceName, version, status);
Map<GraphPropertyEnum, Object> propertiesNotToMatch = new EnumMap<>(GraphPropertyEnum.class);
propertiesToMatch.put(property, nodeName);
propertiesToMatch.put(GraphPropertyEnum.IS_HIGHEST_VERSION, true);
- propertiesToMatch.put(GraphPropertyEnum.MODEL, model);
propertiesNotToMatch.put(GraphPropertyEnum.IS_DELETED, true);
Either<List<GraphVertex>, JanusGraphOperationStatus> highestResources = janusGraphDao
- .getByCriteria(null, propertiesToMatch, propertiesNotToMatch, parseFlag);
+ .getByCriteria(null, propertiesToMatch, propertiesNotToMatch, parseFlag, model);
if (highestResources.isRight()) {
JanusGraphOperationStatus status = highestResources.right().value();
log.debug("failed to find resource with name {}. status={} ", nodeName, status);
public <T extends Component> Either<T, StorageOperationStatus> getComponentByNameAndVendorRelease(final ComponentTypeEnum componentType,
final String name, final String vendorRelease,
- final JsonParseFlagEnum parseFlag) {
+ final JsonParseFlagEnum parseFlag, final String modelName) {
Map<GraphPropertyEnum, Object> hasProperties = new EnumMap<>(GraphPropertyEnum.class);
Map<GraphPropertyEnum, Object> hasNotProperties = new EnumMap<>(GraphPropertyEnum.class);
hasProperties.put(GraphPropertyEnum.NAME, name);
}
Map<String, Entry<JanusGraphPredicate, Object>> predicateCriteria = getVendorVersionPredicate(vendorRelease);
Either<List<GraphVertex>, JanusGraphOperationStatus> getResourceRes = janusGraphDao.getByCriteria(null, hasProperties, hasNotProperties,
- predicateCriteria, parseFlag);
+ predicateCriteria, parseFlag, modelName);
if (getResourceRes.isRight()) {
JanusGraphOperationStatus status = getResourceRes.right().value();
log.debug("failed to find resource with name {}, version {}. Status is {} ", name, predicateCriteria, status);
Map<GraphPropertyEnum, Object> hasNotProps = new EnumMap<>(GraphPropertyEnum.class);
fillPropsMap(hasProps, hasNotProps, internalComponentType, componentTypeEnum, isAbstract, vertexType, modelName);
Either<List<GraphVertex>, JanusGraphOperationStatus> getRes = janusGraphDao
- .getByCriteria(vertexType, hasProps, hasNotProps, JsonParseFlagEnum.ParseMetadata);
+ .getByCriteria(vertexType, hasProps, hasNotProps, JsonParseFlagEnum.ParseMetadata, modelName);
if (getRes.isRight() && !JanusGraphOperationStatus.NOT_FOUND.equals(getRes.right().value())) {
return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(getRes.right().value()));
}
ComponentParametersView params = new ComponentParametersView(true);
params.setIgnoreAllVersions(false);
if (getRes.isLeft()) {
- for (GraphVertex vertexComponent : getVerticesForModel(modelName, getRes.left().value())) {
+ for (GraphVertex vertexComponent : getRes.left().value()) {
Either<ToscaElement, StorageOperationStatus> componentRes = topologyTemplateOperation
.getLightComponent(vertexComponent, componentTypeEnum, params);
if (componentRes.isRight()) {
final ComponentTypeEnum componentType) {
final String normalizedName = ValidationUtils.normaliseComponentName(resourceName);
final Either<List<GraphVertex>, JanusGraphOperationStatus> vertexEither = janusGraphDao
- .getByCriteria(getVertexTypeEnum(resourceType), propertiesToMatch(normalizedName, componentType), null, null, JsonParseFlagEnum.NoParse);
+ .getByCriteria(getVertexTypeEnum(resourceType), propertiesToMatch(normalizedName, componentType), null, null, JsonParseFlagEnum.NoParse, modelName);
if (vertexEither.isRight() && vertexEither.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
log.debug("failed to get vertex from graph with property normalizedName: {} and model: {}", normalizedName, modelName);
return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(vertexEither.right().value()));
}
return Either.left(CollectionUtils.isEmpty(vertexEither.isLeft() ? vertexEither.left().value().stream()
- .filter(graphVertex -> graphVertex.getMetadataProperty(GraphPropertyEnum.NAME).equals(modelName)).collect(Collectors.toList()) : null));
+ .collect(Collectors.toList()) : null));
}
private VertexTypeEnum getVertexTypeEnum(final ResourceTypeEnum resourceType) {
}
public <T extends Component> Either<T, StorageOperationStatus> getLatestByNameAndVersion(String name, String version,
- JsonParseFlagEnum parseFlag) {
+ JsonParseFlagEnum parseFlag, String model) {
Either<T, StorageOperationStatus> result;
Map<GraphPropertyEnum, Object> hasProperties = new EnumMap<>(GraphPropertyEnum.class);
Map<GraphPropertyEnum, Object> hasNotProperties = new EnumMap<>(GraphPropertyEnum.class);
hasProperties.put(GraphPropertyEnum.IS_HIGHEST_VERSION, true);
hasNotProperties.put(GraphPropertyEnum.IS_DELETED, true);
Either<List<GraphVertex>, JanusGraphOperationStatus> getResourceRes = janusGraphDao
- .getByCriteria(null, hasProperties, hasNotProperties, parseFlag);
+ .getByCriteria(null, hasProperties, hasNotProperties, parseFlag, model);
if (getResourceRes.isRight()) {
JanusGraphOperationStatus status = getResourceRes.right().value();
log.debug("failed to find resource with name {}, version {}. Status is {} ", name, version, status);
return null;
}
- public Either<Boolean, StorageOperationStatus> validateToscaResourceNameExtends(String templateNameCurrent, String templateNameExtends) {
+ public Either<Boolean, StorageOperationStatus> validateToscaResourceNameExtends(String templateNameCurrent, String templateNameExtends, String model) {
String currentTemplateNameChecked = templateNameExtends;
while (currentTemplateNameChecked != null && !currentTemplateNameChecked.equalsIgnoreCase(templateNameCurrent)) {
- Either<Resource, StorageOperationStatus> latestByToscaResourceName = getLatestByToscaResourceName(currentTemplateNameChecked);
+ Either<Resource, StorageOperationStatus> latestByToscaResourceName = getLatestByToscaResourceName(currentTemplateNameChecked, model);
if (latestByToscaResourceName.isRight()) {
return latestByToscaResourceName.right().value() == StorageOperationStatus.NOT_FOUND ? Either.left(false)
: Either.right(latestByToscaResourceName.right().value());
Map<GraphPropertyEnum, Object> propertiesNotToMatch,
String modelName) {
Either<List<GraphVertex>, JanusGraphOperationStatus> getRes = janusGraphDao
- .getByCriteria(VertexTypeEnum.TOPOLOGY_TEMPLATE, propertiesToMatch, propertiesNotToMatch, JsonParseFlagEnum.ParseAll);
+ .getByCriteria(VertexTypeEnum.TOPOLOGY_TEMPLATE, propertiesToMatch, propertiesNotToMatch, JsonParseFlagEnum.ParseAll, modelName);
if (getRes.isRight()) {
if (getRes.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG,
return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(getRes.right().value()));
}
} else {
- for (final GraphVertex vertex : getVerticesForModel(modelName, getRes.left().value())) {
+ for (final GraphVertex vertex : getRes.left().value()) {
Either<ToscaElement, StorageOperationStatus> getServiceRes = topologyTemplateOperation
.getLightComponent(vertex, ComponentTypeEnum.SERVICE, new ComponentParametersView(true));
if (getServiceRes.isRight()) {
Either<List<CategoryDefinition>, ActionStatus> getAllCategories(NodeTypeEnum nodeType, boolean inTransaction);
- List<BaseType> getBaseTypes(String categoryName);
+ List<BaseType> getBaseTypes(String categoryName, String modelName);
Either<CategoryDefinition, ActionStatus> getCategory(NodeTypeEnum nodeType, String categoryId);
}
@Override
- public List<BaseType> getBaseTypes(final String categoryName){
+ public List<BaseType> getBaseTypes(final String categoryName, final String modelName){
final ArrayList<BaseType> baseTypes = new ArrayList<>();
final Map<String, String> categoriesSpecificBaseTypes = ConfigurationManager.getConfigurationManager().getConfiguration().getServiceNodeTypes();
final String categorySpecificBaseType = categoriesSpecificBaseTypes == null ? null : categoriesSpecificBaseTypes.get(categoryName);
props.put(GraphPropertyEnum.TOSCA_RESOURCE_NAME, baseToscaResourceName);
props.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name());
final Either<List<GraphVertex>, JanusGraphOperationStatus> baseTypeVertex = janusGraphDao
- .getByCriteria(VertexTypeEnum.NODE_TYPE, props, JsonParseFlagEnum.ParseAll);
-
+ .getByCriteria(VertexTypeEnum.NODE_TYPE, props, null, JsonParseFlagEnum.ParseAll, modelName);
+
if (baseTypeVertex.isLeft()) {
BaseType baseType = new BaseType(baseToscaResourceName);
baseTypes.add(baseType);
Map<GraphPropertyEnum, Object> propertiesNotToMatch = new EnumMap<>(GraphPropertyEnum.class);
propertiesToMatch.put(GraphPropertyEnum.TOSCA_RESOURCE_NAME, "toscaResourceName");
propertiesToMatch.put(GraphPropertyEnum.IS_HIGHEST_VERSION, true);
- propertiesToMatch.put(GraphPropertyEnum.MODEL, null);
propertiesNotToMatch.put(GraphPropertyEnum.IS_DELETED, true);
- when(janusGraphDaoMock.getByCriteria(null, propertiesToMatch, propertiesNotToMatch, JsonParseFlagEnum.ParseAll))
+ when(janusGraphDaoMock.getByCriteria(null, propertiesToMatch, propertiesNotToMatch, JsonParseFlagEnum.ParseAll, null))
.thenReturn(Either.left(list));
when(topologyTemplateOperationMock.getToscaElement(ArgumentMatchers.eq(graphVertex), any(ComponentParametersView.class)))
.thenReturn(Either.left(toscaElement));
public void testGetLatestByToscaResourceName() {
Either<Component, StorageOperationStatus> result;
String toscaResourceName = "name";
+ String model = "testModel";
ToscaElement toscaElement = getToscaElementForTest();
Map<GraphPropertyEnum, Object> propertiesToMatch = new EnumMap<>(GraphPropertyEnum.class);
propertiesToMatch.put(GraphPropertyEnum.TOSCA_RESOURCE_NAME, toscaResourceName);
propertiesToMatch.put(GraphPropertyEnum.IS_HIGHEST_VERSION, true);
- propertiesToMatch.put(GraphPropertyEnum.MODEL, null);
Map<GraphPropertyEnum, Object> propertiesNotToMatch = new EnumMap<>(GraphPropertyEnum.class);
propertiesNotToMatch.put(GraphPropertyEnum.IS_DELETED, true);
graphVertex.setMetadataProperties(props);
graphVertexList.add(graphVertex);
- when(janusGraphDaoMock.getByCriteria(null, propertiesToMatch, propertiesNotToMatch, JsonParseFlagEnum.ParseMetadata))
+ when(janusGraphDaoMock.getByCriteria(null, propertiesToMatch, propertiesNotToMatch, JsonParseFlagEnum.ParseMetadata, model))
.thenReturn(Either.left(graphVertexList));
when(topologyTemplateOperationMock.getToscaElement(any(GraphVertex.class), any(ComponentParametersView.class)))
.thenReturn(Either.left(toscaElement));
- result = testInstance.getLatestByToscaResourceName(toscaResourceName);
+ result = testInstance.getLatestByToscaResourceName(toscaResourceName, model);
assertTrue(result.isLeft());
}
GraphVertex baseTypeVertex = mock(GraphVertex.class);
when(baseTypeVertex.getMetadataProperty(GraphPropertyEnum.VERSION)).thenReturn("1.0");
- when(healingJanusGraphDao.getByCriteria(any(), any(), any()))
+ when(healingJanusGraphDao.getByCriteria(eq(VertexTypeEnum.NODE_TYPE), any(), isNull(), eq(JsonParseFlagEnum.ParseAll), any()))
.thenReturn(Either.left(Collections.singletonList(baseTypeVertex)));
GraphVertex derivedTypeVertex = mock(GraphVertex.class);
when(derivedTypeVertex.getMetadataProperty(GraphPropertyEnum.TOSCA_RESOURCE_NAME))
.thenReturn("org.parent.type");
- List<BaseType> baseTypes = elementOperation.getBaseTypes("serviceCategoryA");
+ List<BaseType> baseTypes = elementOperation.getBaseTypes("serviceCategoryA", null);
assertEquals(2, baseTypes.size());
assertEquals("org.base.type", baseTypes.get(0).getToscaResourceName());
GraphVertex baseTypeVertex = mock(GraphVertex.class);
when(baseTypeVertex.getMetadataProperty(GraphPropertyEnum.VERSION)).thenReturn("1.0");
- when(healingJanusGraphDao.getByCriteria(any(), any(), any()))
+ when(healingJanusGraphDao.getByCriteria(eq(VertexTypeEnum.NODE_TYPE), any(), isNull(), eq(JsonParseFlagEnum.ParseAll), any()))
.thenReturn(Either.left(Collections.singletonList(baseTypeVertex)));
when(healingJanusGraphDao.getParentVertices(baseTypeVertex, EdgeLabelEnum.DERIVED_FROM,
JsonParseFlagEnum.ParseAll)).thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND));
- List<BaseType> baseTypes = elementOperation.getBaseTypes("serviceCategoryA");
+ List<BaseType> baseTypes = elementOperation.getBaseTypes("serviceCategoryA", null);
assertEquals(1, baseTypes.size());
assertEquals("org.service.default", baseTypes.get(0).getToscaResourceName());
public categorySpecificMetadata: Metadata = new Metadata();
public derivedFromGenericType: string;
public derivedFromGenericVersion: string;
- public model: Model;
+ public model: string;
constructor(componentService:IComponentService, protected $q:ng.IQService, component?:Component) {
if (component) {
}
/*** addProperty ***/
- addProperty = (model: Model) => {
+ addProperty = (model: string) => {
this.loadDataTypesByComponentModel(model)
let modalTitle = 'Add Property';
let modal = this.ModalService.createCustomModal(new ModalModel(
return instanceType === ResourceType.VF || instanceType === ResourceType.PNF || instanceType === ResourceType.CVFC || instanceType === ResourceType.CR;
}
- loadDataTypesByComponentModel(model:Model) {
- let modelName = new Model(model).name;
- this.propertyCreatorComponent.filterDataTypesByModel(modelName);
+ loadDataTypesByComponentModel(model:string) {
+ this.propertyCreatorComponent.filterDataTypesByModel(model);
}
}
this.baseUrl = sdcConfig.api.root;
}
- getCategoryBasetypes(categoryName:string):Observable<BaseTypeResponse[]> {
- return this.http.get<ListBaseTypesResponse>(this.baseUrl + "/v1/category/services/" + categoryName + "/baseTypes")
+ getCategoryBasetypes(categoryName:string, modelName:string):Observable<BaseTypeResponse[]> {
+ let modelQueryParam: string = modelName ? '?model=' + modelName : '';
+ return this.http.get<ListBaseTypesResponse>(this.baseUrl + "/v1/category/services/" + categoryName + "/baseTypes" + modelQueryParam)
.pipe(map(response => response.baseTypes));
}
public substitutionFilters: any;
public derivedFromGenericType;
public derivedFromGenericVersion;
- public model:Model;
+ public model:string;
deserialize (response): ComponentGenericResponse {
this.$scope.property = new PropertyModel(this.originalProperty); //we create a new Object so if user press cance we won't update the property
this.$scope.types = PROPERTY_DATA.TYPES; //All types - simple type + map + list
this.$scope.simpleTypes = PROPERTY_DATA.SIMPLE_TYPES; //All simple types
- this.$scope.dataTypes = this.DataTypesService.getAllDataTypesFromModel(this.component.model.name); //Get all data types in service
+ this.$scope.dataTypes = this.DataTypesService.getAllDataTypesFromModel(this.component.model); //Get all data types in service
this.$scope.modalPropertyFormBase = this.$uibModalInstance;
this.$scope.isNew = !angular.isDefined(this.$scope.property.name);
this.$templateCache.put("select-datatype-modal-view.html", require('app/view-models/forms/property-forms/select-datatype-modal/select-datatype-modal-view.html'));
this.$scope.innerViewSrcUrl = "select-datatype-modal-view.html";
- this.$scope.modelNameFilter = this.component.model.name;
+ this.$scope.modelNameFilter = this.component.model;
this.initChildScope();
}
this.$scope.initBaseTypes = ():void => {
if (this.$scope.componentType === ComponentType.SERVICE && this.$scope.component && this.$scope.component.categories) {
- this.elementService.getCategoryBasetypes(this.$scope.component.categories[0].name).subscribe((data: BaseTypeResponse[]) => {
+ let modelName = this.$scope.component.model ? this.$scope.component.model : null;
+ this.elementService.getCategoryBasetypes(this.$scope.component.categories[0].name, modelName).subscribe((data: BaseTypeResponse[]) => {
this.$scope.baseTypes = []
this.$scope.baseTypeVersions = []
data.forEach(baseType => {
}
}
if (this.$scope.componentType === ComponentType.SERVICE && this.$scope.component.categories[0]) {
- this.elementService.getCategoryBasetypes(this.$scope.component.categories[0].name).subscribe((data: BaseTypeResponse[]) => {
+ let modelName : string = this.$scope.component.model ? this.$scope.component.model : null;
+ this.elementService.getCategoryBasetypes(this.$scope.component.categories[0].name, modelName).subscribe((data: BaseTypeResponse[]) => {
if(this.$scope.isCreateMode()){
this.$scope.baseTypes = []
};
this.$scope.onBaseTypeChange = (): void => {
- this.elementService.getCategoryBasetypes(this.$scope.component.categories[0].name).subscribe((data: BaseTypeResponse[]) => {
+ let modelName : string = this.$scope.component.model ? this.$scope.component.model : null;
+ this.elementService.getCategoryBasetypes(this.$scope.component.categories[0].name, modelName).subscribe((data: BaseTypeResponse[]) => {
this.$scope.baseTypeVersions = []
data.forEach(baseType => {
if(baseType.toscaResourceName === this.$scope.component.derivedFromGenericType) {
})
};
+ this.$scope.onModelChange = (): void => {
+ if (this.$scope.componentType === ComponentType.SERVICE && this.$scope.component && this.$scope.component.categories) {
+ let modelName = this.$scope.component.model ? this.$scope.component.model : null;
+ this.elementService.getCategoryBasetypes(this.$scope.component.categories[0].name, modelName).subscribe((data: BaseTypeResponse[]) => {
+ this.$scope.baseTypes = []
+ this.$scope.baseTypeVersions = []
+ data.forEach(baseType => this.$scope.baseTypes.push(baseType.toscaResourceName));
+ data[0].versions.reverse().forEach(version => this.$scope.baseTypeVersions.push(version));
+ this.$scope.component.derivedFromGenericType = data[0].toscaResourceName;
+ this.$scope.component.derivedFromGenericVersion = data[0].versions[0];
+ })
+ }
+ };
+
this.$scope.onVendorNameChange = (oldVendorName: string): void => {
if (this.$scope.component.icon === oldVendorName) {
this.$scope.component.icon = DEFAULT_ICON;
data-ng-class="{'view-mode': isViewMode()}"
data-ng-disabled="component.isCsarComponent() || !isCreateMode()"
data-ng-model="component.model"
+ data-ng-change="onModelChange()"
data-tests-id="modelName">
<option value="">SDC AID</option>
<option ng-repeat="model in models | orderBy:[name]">{{model}}</option>