import fj.data.Either;
import java.lang.reflect.Type;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.HashSet;
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.GraphPropertiesDictionary;
+import org.openecomp.sdc.be.datatypes.category.MetadataKeyDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.AdditionalInfoParameterDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.AttributeDataDefinition;
}
public Either<GraphVertex, StorageOperationStatus> markComponentToDelete(GraphVertex componentToDelete) {
- Either<GraphVertex, StorageOperationStatus> result = null;
-
Boolean isDeleted = (Boolean) componentToDelete.getMetadataProperty(GraphPropertyEnum.IS_DELETED);
if (isDeleted != null && isDeleted && !(Boolean) componentToDelete.getMetadataProperty(GraphPropertyEnum.IS_HIGHEST_VERSION)) {
// component already marked for delete
- result = Either.left(componentToDelete);
- return result;
} else {
-
componentToDelete.addMetadataProperty(GraphPropertyEnum.IS_DELETED, Boolean.TRUE);
componentToDelete.setJsonMetadataField(JsonPresentationFields.LAST_UPDATE_DATE, System.currentTimeMillis());
if (updateNode.isRight()) {
log.debug("Failed to update component {}. status is {}", componentToDelete.getUniqueId(), updateNode.right().value());
updateComponent = DaoStatusConverter.convertJanusGraphStatusToStorageStatus(updateNode.right().value());
- result = Either.right(updateComponent);
- return result;
+ return Either.right(updateComponent);
}
-
- result = Either.left(componentToDelete);
- return result;
}
+ return Either.left(componentToDelete);
}
/**
nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.IS_ARCHIVED, toscaElement.getMetadataValue(JsonPresentationFields.IS_ARCHIVED));
nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.ARCHIVE_TIME, toscaElement.getMetadataValue(JsonPresentationFields.ARCHIVE_TIME));
nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.IS_VSP_ARCHIVED, toscaElement.getMetadataValue(JsonPresentationFields.IS_VSP_ARCHIVED));
- toscaElement.getMetadata().entrySet().stream().filter(e -> e.getValue() != null).forEach(e -> nodeTypeVertex.setJsonMetadataField(JsonPresentationFields.getByPresentation(e.getKey()), e.getValue()));
+ toscaElement.getMetadata().entrySet().stream().filter(e -> e.getValue() != null).forEach(e -> nodeTypeVertex.setJsonMetadataField(e.getKey(), e.getValue()));
nodeTypeVertex.setUniqueId(toscaElement.getUniqueId());
nodeTypeVertex.setType(toscaElement.getComponentType());
return JanusGraphOperationStatus.OK;
}
+ protected StorageOperationStatus assosiateCommonForToscaElement(GraphVertex nodeTypeVertex, ToscaElement toscaElement) {
+ return assosiateCommonForToscaElement(nodeTypeVertex, toscaElement, null);
+ }
+
protected StorageOperationStatus assosiateCommonForToscaElement(GraphVertex nodeTypeVertex, ToscaElement toscaElement, List<GraphVertex> derivedResources) {
StorageOperationStatus associateUsers = assosiateToUsers(nodeTypeVertex, toscaElement);
protected <T extends ToscaElement> Either<List<T>, StorageOperationStatus> getFollowedComponent(String userId, Set<LifecycleStateEnum> lifecycleStates, Set<LifecycleStateEnum> lastStateStates, ComponentTypeEnum neededType) {
- Either<List<T>, StorageOperationStatus> result = null;
-
Map<GraphPropertyEnum, Object> props = null;
if (userId != null) {
}
} // whlile users
- ;
- result = Either.left(components);
- return result;
-
+ return Either.left(components);
}
private <T extends ToscaElement> List<T> fetchComponents(String userId, Set<LifecycleStateEnum> lifecycleStates, List<GraphVertex> vertices, ComponentTypeEnum neededType, EdgeLabelEnum edgelabel) {
switch (label) {
case NODE_TYPE:
toscaElement = new NodeType();
- ((NodeType) toscaElement).setAttributes(getAttributesFromComponentV(componentV));
break;
case TOPOLOGY_TEMPLATE:
toscaElement = new TopologyTemplate();
return dataType;
}
- private Map<String, AttributeDataDefinition> getAttributesFromComponentV(final GraphVertex componentV) {
- final Map<String, Object> jsonMetada = componentV.getMetadataJson();
- final Map<String, AttributeDataDefinition> attributeDataDefinitionMap = new HashMap<>();
- if (MapUtils.isNotEmpty(jsonMetada)) {
- final Object attributes = jsonMetada.get(ToscaTagNamesEnum.ATTRIBUTES.getElementName());
- if (attributes instanceof Map) {
- final Map<String, Object> map = (Map<String, Object>) attributes;
- attributeDataDefinitionMap.putAll(map.values().stream().map(attributeMap -> {
- final AttributeDataDefinition attributeDef = new AttributeDataDefinition();
- final String name = (String) ((Map<String, Object>) attributeMap).get("name");
- attributeDef.setName(name);
- final String type = (String) ((Map<String, Object>) attributeMap).get("type");
- attributeDef.setType(type);
- final String description = (String) ((Map<String, Object>) attributeMap).get("description");
- attributeDef.setDescription(description);
- final Object _default = ((Map<String, Object>) attributeMap).get("_default");
- attributeDef.set_default(_default);
- final String status = (String) ((Map<String, Object>) attributeMap).get("status");
- attributeDef.setStatus(status);
- final EntrySchema entry_schema = (EntrySchema) ((Map<String, Object>) attributeMap).get("entry_schema");
- attributeDef.setEntry_schema(entry_schema);
- return attributeDef;
- }).collect(Collectors.toMap(AttributeDataDefinition::getName, a -> a)));
- }
- }
- return attributeDataDefinitionMap;
- }
-
protected JanusGraphOperationStatus setResourceCategoryFromGraphV(Vertex vertex, CatalogComponent catalogComponent) {
List<CategoryDefinition> categories = new ArrayList<>();
SubCategoryDefinition subcategory;
subcategory.setUniqueId((String) subCategoryV.property(GraphPropertyEnum.UNIQUE_ID.getProperty()).value());
subcategory.setNormalizedName(subCategoryNormalizedName);
subcategory.setName((String) subCategoryV.property(GraphPropertyEnum.NAME.getProperty()).value());
+
+ Type listTypeSubcat = new TypeToken<List<MetadataKeyDataDefinition>>() {
+ }.getType();
+ List<MetadataKeyDataDefinition> metadataKeys =
+ subCategoryV.property(GraphPropertyEnum.METADATA_KEYS.getProperty()).isPresent() ? getGson().fromJson(
+ (String) subCategoryV.property(GraphPropertyEnum.METADATA_KEYS.getProperty()).value(),
+ listTypeSubcat) : Collections.emptyList();
+ subcategory.setMetadataKeys(metadataKeys);
+
Either<Vertex, JanusGraphOperationStatus> parentVertex = janusGraphDao.getParentVertex(subCategoryV, EdgeLabelEnum.SUB_CATEGORY, JsonParseFlagEnum.NoParse);
Vertex categoryV = parentVertex.left().value();
String categoryNormalizedName = (String) categoryV.property(GraphPropertyEnum.NORMALIZED_NAME.getProperty()).value();
category.setName((String) categoryV.property(GraphPropertyEnum.NAME.getProperty()).value());
category.setUseServiceSubstitutionForNestedServices((Boolean) categoryV.property(GraphPropertyEnum.USE_SUBSTITUTION_FOR_NESTED_SERVICES.getProperty()).orElse(false));
+ Type listTypeCat = new TypeToken<List<MetadataKeyDataDefinition>>() {
+ }.getType();
+ List<MetadataKeyDataDefinition> metadataKeys =
+ categoryV.property(GraphPropertyEnum.METADATA_KEYS.getProperty()).isPresent() ? getGson().fromJson(
+ (String) categoryV.property(GraphPropertyEnum.METADATA_KEYS.getProperty()).value(), listTypeCat)
+ : Collections.emptyList();
+ category.setMetadataKeys(metadataKeys);
+
categories.add(category);
catalogComponent.setCategories(categories);
return JanusGraphOperationStatus.OK;
List<String> iconsfromJsonSubcat = getGson().fromJson((String) metadataProperties.get(GraphPropertyEnum.ICONS), listTypeSubcat);
subcategory.setIcons(iconsfromJsonSubcat);
+ final Type metadataKeysTypeCat = new TypeToken<List<MetadataKeyDataDefinition>>() {}.getType();
+ final List<MetadataKeyDataDefinition> metadataKeysfromJsonCat = getGson().fromJson((String) metadataProperties.get(GraphPropertyEnum.METADATA_KEYS), metadataKeysTypeCat);
+ subcategory.setMetadataKeys(metadataKeysfromJsonCat);
+
Either<GraphVertex, JanusGraphOperationStatus> parentVertex = janusGraphDao
.getParentVertex(subCategoryV, EdgeLabelEnum.SUB_CATEGORY, JsonParseFlagEnum.NoParse);
if (parentVertex.isRight()) {