summaryrefslogtreecommitdiffstats
path: root/dcaedt_be/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'dcaedt_be/src/main')
-rw-r--r--dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/controller/BaseController.java60
-rw-r--r--dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/controller/BlueprintController.java68
-rw-r--r--dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/controller/CompositionController.java212
-rw-r--r--dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/controller/ConfigurationController.java2
-rw-r--r--dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/controller/LifecycleController.java11
-rw-r--r--dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/controller/RuleEditorController.java9
-rw-r--r--dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/controller/VfcmtController.java3
-rw-r--r--dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/impl/BaseBusinessLogic.java34
-rw-r--r--dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/impl/BlueprintBusinessLogic.java12
-rw-r--r--dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/impl/CompositionBusinessLogic.java9
-rw-r--r--dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/impl/CompositionCatalogBusinessLogic.java205
-rw-r--r--dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/impl/ReferenceBusinessLogic.java2
-rw-r--r--dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/impl/RuleEditorBusinessLogic.java1
-rw-r--r--dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/impl/ServiceBusinessLogic.java48
-rw-r--r--dcaedt_be/src/main/java/org/onap/sdc/dcae/rule/editor/validators/RuleValidator.java4
15 files changed, 337 insertions, 343 deletions
diff --git a/dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/controller/BaseController.java b/dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/controller/BaseController.java
index 818a30d..131efad 100644
--- a/dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/controller/BaseController.java
+++ b/dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/controller/BaseController.java
@@ -1,37 +1,23 @@
package org.onap.sdc.dcae.composition.controller;
-import javax.servlet.http.HttpServletRequest;
-
+import com.google.gson.Gson;
+import org.onap.sdc.common.onaplog.Enums.LogLevel;
import org.onap.sdc.common.onaplog.OnapLoggerDebug;
import org.onap.sdc.common.onaplog.OnapLoggerError;
-import org.onap.sdc.common.onaplog.Enums.LogLevel;
import org.onap.sdc.dcae.composition.impl.BaseBusinessLogic;
-import org.onap.sdc.dcae.composition.restmodels.sdc.Asset;
-import org.onap.sdc.dcae.composition.restmodels.sdc.ResourceDetailed;
-import org.onap.sdc.dcae.composition.util.DcaeBeConstants;
-import org.onap.sdc.dcae.composition.util.SystemProperties;
-import org.onap.sdc.dcae.enums.AssetType;
-import org.onap.sdc.dcae.enums.LifecycleOperationType;
-import org.onap.sdc.dcae.errormng.ActionStatus;
-import org.onap.sdc.dcae.errormng.DcaeException;
import org.onap.sdc.dcae.errormng.ErrConfMgr;
import org.onap.sdc.dcae.errormng.ErrConfMgr.ApiType;
-import org.onap.sdc.dcae.errormng.ResponseFormat;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ModelAttribute;
-import com.google.gson.Gson;
+import javax.servlet.http.HttpServletRequest;
public abstract class BaseController {
protected Gson gson = new Gson();
@Autowired
- protected SystemProperties systemProperties;
-
- @Autowired
protected BaseBusinessLogic baseBusinessLogic;
protected OnapLoggerError errLogger = OnapLoggerError.getInstance();
@@ -42,48 +28,8 @@ public abstract class BaseController {
return request.getAttribute("requestId").toString();
}
- ResourceDetailed checkoutVfcmt(String userId, String uuid, String requestId) {
- return baseBusinessLogic.getSdcRestClient().changeResourceLifecycleState(userId, uuid, LifecycleOperationType.CHECKOUT.name(), null, requestId);
- }
-
- ResourceDetailed checkinVfcmt(String userId, String uuid, String requestId) {
- return baseBusinessLogic.getSdcRestClient().changeResourceLifecycleState(userId, uuid, LifecycleOperationType.CHECKIN.name(), "checking in vfcmt" + uuid, requestId);
- }
-
-
- boolean isNeedToCheckOut(String lifecycleState) {
- return DcaeBeConstants.LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT != DcaeBeConstants.LifecycleStateEnum.findState(lifecycleState);
- }
-
- void checkUserIfResourceCheckedOut(String userId, Asset asset) {
- if (DcaeBeConstants.LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT == DcaeBeConstants.LifecycleStateEnum.findState(asset.getLifecycleState())) {
- String lastUpdaterUserId = asset.getLastUpdaterUserId();
- if (lastUpdaterUserId != null && !lastUpdaterUserId.equals(userId)) {
- errLogger.log(LogLevel.ERROR, this.getClass().getName(), "User conflicts. Operation not allowed for user {} on resource checked out by {}", userId, lastUpdaterUserId);
- ResponseFormat responseFormat = ErrConfMgr.INSTANCE.getResponseFormat(ActionStatus.USER_CONFLICT, null, userId, asset.getName(), lastUpdaterUserId);
- throw new DcaeException(HttpStatus.FORBIDDEN, responseFormat.getRequestError());
- }
- }
- }
-
- void checkVfcmtType(ResourceDetailed vfcmt) {
- if (AssetType.VFCMT != getValidAssetTypeOrNull(vfcmt.getResourceType()) || !"Template".equals(vfcmt.getCategory())) {
- ResponseFormat responseFormat = ErrConfMgr.INSTANCE.getResponseFormat(ActionStatus.RESOURCE_NOT_VFCMT_ERROR, null, vfcmt.getUuid());
- throw new DcaeException(HttpStatus.BAD_REQUEST, responseFormat.getRequestError());
- }
- }
-
ResponseEntity handleException(Exception e, ApiType apiType, String... variables){
errLogger.log(LogLevel.ERROR, this.getClass().getName(), e.getMessage());
return ErrConfMgr.INSTANCE.handleException(e, apiType, variables);
}
-
- AssetType getValidAssetTypeOrNull(String type) {
- try {
- return AssetType.getAssetTypeByName(type);
- } catch (IllegalArgumentException e) {
- debugLogger.log(LogLevel.ERROR, this.getClass().getName(), "invalid asset type: {}. Error: {}", type, e);
- return null;
- }
- }
}
diff --git a/dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/controller/BlueprintController.java b/dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/controller/BlueprintController.java
index 5f4cee7..0d638d9 100644
--- a/dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/controller/BlueprintController.java
+++ b/dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/controller/BlueprintController.java
@@ -7,48 +7,44 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
-import javax.annotation.PostConstruct;
-
@RestController
@EnableAutoConfiguration
@CrossOrigin
public class BlueprintController extends BaseController {
- @Autowired
- private BlueprintBusinessLogic blueprintBusinessLogic;
+ @Autowired
+ private BlueprintBusinessLogic blueprintBusinessLogic;
- @PostConstruct
- public void init(){
+ /***
+ * VFCMT - Resource, blueprint - as an artifact as an service.
+ * @param context
+ * @param userId
+ * @param vfcmtUuid
+ * @param serviceUuid
+ * @param instanceName
+ * @param requestId
+ * @return ResponseEntity
+ */
+ @RequestMapping(value = "{context}/createBluePrint/{VFCMTUuid}/{serviceUuid}/{instanceName}", method = RequestMethod.POST)
+ public ResponseEntity createBlueprint(
+ @RequestHeader("USER_ID") String userId,
+ @PathVariable String context,
+ @PathVariable("VFCMTUuid") String vfcmtUuid,
+ @PathVariable("serviceUuid") String serviceUuid,
+ @PathVariable("instanceName") String instanceName,
+ @ModelAttribute("requestId") String requestId) {
+ return blueprintBusinessLogic.generateAndSaveBlueprint(userId, context, vfcmtUuid, serviceUuid, instanceName, "", requestId);
}
- /***
- * VFCMT - Resource, blueprint - as an artifact as an service.
- * @param context
- * @param userId
- * @param vfcmtUuid
- * @param serviceUuid
- * @param instanceName
- * @param requestId
- * @return ResponseEntity
- */
- @RequestMapping(value = "{context}/createBluePrint/{VFCMTUuid}/{serviceUuid}/{instanceName}", method = RequestMethod.POST)
- public ResponseEntity createBlueprint(@RequestHeader("USER_ID") String userId,
- @PathVariable String context,
- @PathVariable("VFCMTUuid") String vfcmtUuid,
- @PathVariable("serviceUuid") String serviceUuid,
- @PathVariable("instanceName") String instanceName,
- @ModelAttribute("requestId") String requestId) {
- return blueprintBusinessLogic.generateAndSaveBlueprint(userId, context, vfcmtUuid, serviceUuid, instanceName, "", requestId);
- }
-
- @Deprecated
- @RequestMapping(value = "/createBluePrint/{VFCMTUuid}/{serviceUuid}/{instanceName}/{monitoringFlowType}", method = RequestMethod.POST)
- public ResponseEntity createBluePrintWithFlowType(@RequestHeader("USER_ID") String userId,
- @PathVariable("VFCMTUuid") String vfcmtUuid,
- @PathVariable("serviceUuid") String serviceUuid,
- @PathVariable("instanceName") String serviceInstanceName,
- @PathVariable("monitoringFlowType") String monitoringFlowType,
- @ModelAttribute("requestId") String requestId) {
- return blueprintBusinessLogic.generateAndSaveBlueprint(userId, AssetType.SERVICE.name(), vfcmtUuid, serviceUuid, serviceInstanceName, monitoringFlowType, requestId);
- }
+ @Deprecated
+ @RequestMapping(value = "/createBluePrint/{VFCMTUuid}/{serviceUuid}/{instanceName}/{monitoringFlowType}", method = RequestMethod.POST)
+ public ResponseEntity createBluePrintWithFlowType(
+ @RequestHeader("USER_ID") String userId,
+ @PathVariable("VFCMTUuid") String vfcmtUuid,
+ @PathVariable("serviceUuid") String serviceUuid,
+ @PathVariable("instanceName") String instanceName,
+ @PathVariable("monitoringFlowType") String monitoringFlowType,
+ @ModelAttribute("requestId") String requestId) {
+ return blueprintBusinessLogic.generateAndSaveBlueprint(userId, AssetType.SERVICE.name(), vfcmtUuid, serviceUuid, instanceName, monitoringFlowType, requestId);
+ }
}
diff --git a/dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/controller/CompositionController.java b/dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/controller/CompositionController.java
index 3261ddc..dbcbcc9 100644
--- a/dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/controller/CompositionController.java
+++ b/dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/controller/CompositionController.java
@@ -1,17 +1,15 @@
package org.onap.sdc.dcae.composition.controller;
-import org.json.JSONArray;
-import org.json.JSONException;
import org.onap.sdc.common.onaplog.Enums.LogLevel;
+import org.onap.sdc.dcae.catalog.engine.CatalogResponse;
+import org.onap.sdc.dcae.catalog.engine.ElementRequest;
+import org.onap.sdc.dcae.catalog.engine.ItemsRequest;
import org.onap.sdc.dcae.composition.impl.CompositionBusinessLogic;
+import org.onap.sdc.dcae.composition.impl.CompositionCatalogBusinessLogic;
import org.onap.sdc.dcae.composition.restmodels.MessageResponse;
import org.onap.sdc.dcae.composition.restmodels.ReferenceUUID;
import org.onap.sdc.dcae.composition.restmodels.sdc.Artifact;
-import org.onap.sdc.dcae.composition.restmodels.sdc.Asset;
import org.onap.sdc.dcae.composition.restmodels.sdc.ResourceDetailed;
-import org.onap.sdc.dcae.catalog.Catalog;
-import org.onap.sdc.dcae.catalog.Catalog.*;
-import org.onap.sdc.dcae.catalog.engine.*;
import org.onap.sdc.dcae.composition.util.DcaeBeConstants;
import org.onap.sdc.dcae.enums.LifecycleOperationType;
import org.onap.sdc.dcae.errormng.ActionStatus;
@@ -25,8 +23,6 @@ import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.async.DeferredResult;
-import javax.annotation.PostConstruct;
-import java.net.URI;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -38,22 +34,22 @@ import java.util.stream.Collectors;
@CrossOrigin
public class CompositionController extends BaseController {
- @Autowired private CatalogController catalogController;
+ @Autowired
+ private CompositionCatalogBusinessLogic compositionCatalogBusinessLogic;
- @Autowired private CompositionBusinessLogic compositionBusinessLogic;
+ @Autowired
+ private CompositionBusinessLogic compositionBusinessLogic;
- @PostConstruct public void init() {
- catalogController.setDefaultCatalog(URI.create(systemProperties.getProperties().getProperty(DcaeBeConstants.Config.ASDC_CATALOG_URL)));
- }
-
- @RequestMapping(value = { "/utils/clone/{assetType}/{sourceId}/{targetId}" }, method = { RequestMethod.GET }, produces = { "application/json" }) public ResponseEntity clone(@RequestHeader("USER_ID") String userId,
+ @Deprecated
+ @RequestMapping(value = { "/utils/clone/{assetType}/{sourceId}/{targetId}" }, method = { RequestMethod.GET }, produces = { "application/json" })
+ public ResponseEntity clone(@RequestHeader("USER_ID") String userId,
@PathVariable("assetType") String theAssetType, @PathVariable("sourceId") String theSourceId, @PathVariable("targetId") String theTargetId, @ModelAttribute("requestId") String requestId) {
MessageResponse response = new MessageResponse();
try {
// fetch the source and assert it is a vfcmt containing clone worthy artifacts (composition + rules)
ResourceDetailed sourceVfcmt = baseBusinessLogic.getSdcRestClient().getResource(theSourceId, requestId);
- checkVfcmtType(sourceVfcmt);
+ baseBusinessLogic.checkVfcmtType(sourceVfcmt);
List<Artifact> artifactsToClone = CollectionUtils.isEmpty(sourceVfcmt.getArtifacts()) ?
null :
sourceVfcmt.getArtifacts().stream().filter(p -> DcaeBeConstants.Composition.fileNames.COMPOSITION_YML.equals(p.getArtifactName()) || p.getArtifactName().endsWith(DcaeBeConstants.Composition.fileNames.MAPPING_RULE_POSTFIX))
@@ -66,9 +62,9 @@ public class CompositionController extends BaseController {
// fetch the target
ResourceDetailed vfcmt = baseBusinessLogic.getSdcRestClient().getResource(theTargetId, requestId);
debugLogger.log(LogLevel.DEBUG, this.getClass().getName(), vfcmt.toString());
- checkVfcmtType(vfcmt);
- checkUserIfResourceCheckedOut(userId, vfcmt);
- boolean isTargetNeed2Checkout = isNeedToCheckOut(vfcmt.getLifecycleState());
+ baseBusinessLogic.checkVfcmtType(vfcmt);
+ baseBusinessLogic.checkUserIfResourceCheckedOut(userId, vfcmt);
+ boolean isTargetNeed2Checkout = baseBusinessLogic.isNeedToCheckOut(vfcmt.getLifecycleState());
if (isTargetNeed2Checkout) {
ResourceDetailed targetVfcmt = baseBusinessLogic.getSdcRestClient().changeResourceLifecycleState(userId, theTargetId, LifecycleOperationType.CHECKOUT.name(), "checking out VFCMT before clone", requestId);
if (null == targetVfcmt) {
@@ -95,183 +91,39 @@ public class CompositionController extends BaseController {
}
}
- @RequestMapping(value = "/elements", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json") public DeferredResult<CatalogResponse> items(@RequestBody(required = false) ItemsRequest theRequest) {
-
- final ItemsRequest request = (theRequest == null) ? ItemsRequest.EMPTY_REQUEST : theRequest;
-
- Catalog catalog = catalogController.getCatalog(request.getCatalog());
- DeferredResult<CatalogResponse> result = new DeferredResult<CatalogResponse>(request.getTimeout());
-
- catalog.rootsByLabel(request.getStartingLabel()).setHandler(catalogController.new CatalogHandler<Folders>(request, result) {
- public CatalogResponse handleData(Folders theFolders) {
- JSONArray ja = new JSONArray();
- if (theFolders != null) {
- for (Folder folder : theFolders) {
- ja.put(catalogController.patchData(catalog, folder.data()));
- }
- }
- CatalogResponse response = new CatalogResponse(this.request);
- try {
- response.data().put("elements", ja);
- } catch (JSONException e) {
- errLogger.log(LogLevel.ERROR, this.getClass().getName(), "JSONException putting json elements to response {}", e);
- }
- return response;
- }
- });
- return result;
+ @RequestMapping(value = "/elements", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json")
+ public DeferredResult<CatalogResponse> items(@RequestBody(required = false) ItemsRequest theRequest) {
+ return compositionCatalogBusinessLogic.getItems(theRequest);
}
- @RequestMapping(value = "/{theItemId}/elements", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json") public DeferredResult<CatalogResponse> items(@RequestBody(required = false) ItemsRequest theRequest,
- @PathVariable String theItemId) {
-
- final ItemsRequest request = (theRequest == null) ? ItemsRequest.EMPTY_REQUEST : theRequest;
-
- Catalog catalog = catalogController.getCatalog(request.getCatalog());
- DeferredResult<CatalogResponse> result = new DeferredResult<CatalogResponse>(request.getTimeout());
-
- catalog
- // .fetchFolderByItemId(theItemId)
- .folder(theItemId).withParts().withPartAnnotations().withItems().withItemAnnotations().withItemModels().execute().setHandler(catalogController.new CatalogHandler<Folder>(request, result) {
- public CatalogResponse handleData(Folder theFolder) {
- CatalogResponse response = new CatalogResponse(this.request);
- if (theFolder == null) {
- return response;
- }
-
- try {
- Elements folders = theFolder.elements("parts", Folders.class);
- if (folders != null) {
- for (Object folder : folders) {
- catalogController.patchData(catalog, ((Element) folder).data());
- // lots of ephemere proxies created here ..
- Elements annotations = ((Element) folder).elements("annotations", Annotations.class);
- if (annotations != null) {
- for (Object a : annotations) {
- catalogController.patchData(catalog, ((Annotation) a).data());
- }
- }
- }
- }
- Elements items = theFolder.elements("items", Items.class);
- if (items != null) {
- for (Object i : items) {
- catalogController.patchData(catalog, ((Element) i).data());
- // lots of ephemere proxies created here ..
- Elements annotations = ((Element) i).elements("annotations", Annotations.class);
- if (annotations != null) {
- for (Object a : annotations) {
- catalogController.patchData(catalog, ((Annotation) a).data());
- }
- }
- }
- }
- } catch (Exception x) {
- errLogger.log(LogLevel.ERROR, this.getClass().getName(), "Exception processing catalog {}", x);
- return new CatalogError(this.request, "", x);
- }
-
- try {
- response.data().put("element", theFolder.data());
- } catch (JSONException e) {
- errLogger.log(LogLevel.ERROR, this.getClass().getName(), "JSONException putting element to response {}", e);
- }
- return response;
- }
- });
-
- return result;
+ @RequestMapping(value = "/{theItemId}/elements", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json")
+ public DeferredResult<CatalogResponse> items(@RequestBody(required = false) ItemsRequest theRequest, @PathVariable String theItemId) {
+ return compositionCatalogBusinessLogic.getItemById(theRequest, theItemId);
}
- @RequestMapping(value = "/{theItemId}/model", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json") public DeferredResult model(@RequestBody(required = false) ElementRequest theRequest,
- @PathVariable String theItemId) {
- final ElementRequest request = (theRequest == null) ? ElementRequest.EMPTY_REQUEST : theRequest;
-
- Catalog catalog = catalogController.getCatalog(request.getCatalog());
- DeferredResult<CatalogResponse> result = new DeferredResult<>(request.getTimeout());
-
- catalog.item(theItemId).withModels().execute().setHandler(catalogController.new CatalogHandler<Item>(request, result) {
- public CatalogResponse handleData(Item theItem) {
- if (theItem == null) {
- return new CatalogError(this.request, "No such item");
- }
- Templates models = null;
- try {
- models = (Templates) theItem.elements("models", Templates.class);
- if (models == null || models.isEmpty()) {
- return new CatalogError(this.request, "Item has no models");
- }
- if (models.size() > 1) {
- return new CatalogError(this.request, "Item has more than one model !?");
- }
- catalog.template(models.get(0).id()).withInputs().withOutputs().withNodes().withNodeProperties().withNodePropertiesAssignments().withNodeRequirements().withNodeCapabilities().withNodeCapabilityProperties()
- .withNodeCapabilityPropertyAssignments().withPolicies().withPolicyProperties().withPolicyPropertiesAssignments().execute().setHandler(catalogController.new CatalogHandler<Template>(this.request, this.result) {
- public CatalogResponse handleData(Template theTemplate) {
- CatalogResponse response = new CatalogResponse(this.request);
- if (theTemplate != null) {
- try {
- response.data().put("model", catalogController.patchData(catalog, theTemplate.data()));
- } catch (JSONException e) {
- errLogger.log(LogLevel.ERROR, this.getClass().getName(), "JSONException putting model to response {}", e);
- }
- }
- return response;
- }
- });
- } catch (Exception e) {
- handleException(e, ApiType.GET_MODEL, models.get(0).name());
- }
- return null;
- }
- });
-
- return result;
+ @RequestMapping(value = "/{theItemId}/model", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json")
+ public DeferredResult model(@RequestBody(required = false) ElementRequest theRequest, @PathVariable String theItemId) {
+ return compositionCatalogBusinessLogic.getModelById(theRequest, theItemId);
}
- @RequestMapping(value = "/{theItemId}/type/{theTypeName}", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json") public DeferredResult<CatalogResponse> model(@RequestBody(required = false) ElementRequest theRequest,
- @PathVariable String theItemId, @PathVariable String theTypeName) {
- final ElementRequest request = (theRequest == null) ? ElementRequest.EMPTY_REQUEST : theRequest;
-
- Catalog catalog = catalogController.getCatalog(request.getCatalog());
- DeferredResult<CatalogResponse> result = new DeferredResult<CatalogResponse>(request.getTimeout());
-
- catalog.type(theItemId, theTypeName).withHierarchy().withCapabilities().withRequirements().execute().setHandler(catalogController.new CatalogHandler<Type>(request, result) {
- public CatalogResponse handleData(Type theType) {
- CatalogResponse response = new CatalogResponse(this.request);
- if (theType != null) {
- try {
- response.data().put("type", catalogController.patchData(catalog, theType.data()));
- } catch (JSONException e) {
- errLogger.log(LogLevel.ERROR, this.getClass().getName(), "Exception processing catalog {}", e);
- }
- }
- return response;
- }
- });
-
- return result;
+ @RequestMapping(value = "/{theItemId}/type/{theTypeName}", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json")
+ public DeferredResult<CatalogResponse> model(@RequestBody(required = false) ElementRequest theRequest, @PathVariable String theItemId, @PathVariable String theTypeName) {
+ return compositionCatalogBusinessLogic.getTypeInfo(theRequest, theItemId, theTypeName);
}
- @RequestMapping(value = { "/getComposition/{vfcmtUuid}" }, method = { RequestMethod.GET }, produces = { "application/json" }) public ResponseEntity getComposition(@PathVariable("vfcmtUuid") String vfcmtUuid,
- @ModelAttribute("requestId") String requestId) {
+ @RequestMapping(value = { "/getComposition/{vfcmtUuid}" }, method = { RequestMethod.GET }, produces = { "application/json" })
+ public ResponseEntity getComposition(@PathVariable("vfcmtUuid") String vfcmtUuid, @ModelAttribute("requestId") String requestId) {
MessageResponse response = new MessageResponse();
try {
- ResourceDetailed vfcmt = baseBusinessLogic.getSdcRestClient().getResource(vfcmtUuid, requestId);
- debugLogger.log(LogLevel.DEBUG, this.getClass().getName(), vfcmt.toString());
- checkVfcmtType(vfcmt);
-
- Artifact compositionArtifact = CollectionUtils.isEmpty(vfcmt.getArtifacts()) ? null : vfcmt.getArtifacts().stream().filter(a -> DcaeBeConstants.Composition.fileNames.COMPOSITION_YML.equals(a.getArtifactName())).findAny().orElse(null);
-
+ Artifact compositionArtifact = compositionBusinessLogic.getComposition(vfcmtUuid, requestId);
if (null == compositionArtifact) {
debugLogger.log(LogLevel.DEBUG, this.getClass().getName(), "Couldn't find {} in VFCMT artifacts", DcaeBeConstants.Composition.fileNames.COMPOSITION_YML);
response.setErrorResponse("No Artifacts");
return new ResponseEntity<>(response, HttpStatus.NO_CONTENT);
}
- String artifact = baseBusinessLogic.getSdcRestClient().getResourceArtifact(vfcmtUuid, compositionArtifact.getArtifactUUID(), requestId);
-
- debugLogger.log(LogLevel.DEBUG, this.getClass().getName(), "ARTIFACT: {}", artifact);
- response.setSuccessResponse(artifact);
+ debugLogger.log(LogLevel.DEBUG, this.getClass().getName(), "ARTIFACT: {}", compositionArtifact.getPayloadData());
+ response.setSuccessResponse(compositionArtifact.getPayloadData());
return new ResponseEntity<>(response, HttpStatus.OK);
} catch (Exception e) {
return handleException(e, ApiType.GET_CDUMP);
diff --git a/dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/controller/ConfigurationController.java b/dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/controller/ConfigurationController.java
index 4f083ca..65663f6 100644
--- a/dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/controller/ConfigurationController.java
+++ b/dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/controller/ConfigurationController.java
@@ -26,7 +26,7 @@ import io.swagger.annotations.ApiResponses;
@EnableAutoConfiguration
@CrossOrigin
@RequestMapping("/conf")
-public class ConfigurationController extends BaseController{
+public class ConfigurationController extends BaseController {
@Autowired
private CompositionConfig compositionConfig;
diff --git a/dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/controller/LifecycleController.java b/dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/controller/LifecycleController.java
index 4fa8c18..1c90359 100644
--- a/dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/controller/LifecycleController.java
+++ b/dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/controller/LifecycleController.java
@@ -1,6 +1,5 @@
package org.onap.sdc.dcae.composition.controller;
-import org.onap.sdc.common.onaplog.Enums.LogLevel;
import org.onap.sdc.dcae.composition.restmodels.sdc.ResourceDetailed;
import org.onap.sdc.dcae.enums.AssetType;
import org.onap.sdc.dcae.enums.LifecycleOperationType;
@@ -25,8 +24,8 @@ public class LifecycleController extends BaseController {
@ModelAttribute("requestId") String requestId) {
try {
- if (AssetType.VFCMT == getValidAssetTypeOrNull(assetType)) {
- ResourceDetailed resCheckin = checkinVfcmt(userId, uuid.toString(), requestId);
+ if (AssetType.VFCMT == baseBusinessLogic.getValidAssetTypeOrNull(assetType)) {
+ ResourceDetailed resCheckin = baseBusinessLogic.checkinVfcmt(userId, uuid.toString(), requestId);
return new ResponseEntity<>(resCheckin, HttpStatus.OK);
} else {
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
@@ -44,8 +43,8 @@ public class LifecycleController extends BaseController {
@ModelAttribute("requestId") String requestId) {
try {
- if (AssetType.VFCMT == getValidAssetTypeOrNull(assetType)) {
- ResourceDetailed asset = checkoutVfcmt(userId, uuid.toString(), requestId);
+ if (AssetType.VFCMT == baseBusinessLogic.getValidAssetTypeOrNull(assetType)) {
+ ResourceDetailed asset = baseBusinessLogic.checkoutVfcmt(userId, uuid.toString(), requestId);
return new ResponseEntity<>(asset, HttpStatus.OK);
} else {
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
@@ -63,7 +62,7 @@ public class LifecycleController extends BaseController {
@ModelAttribute("requestId") String requestId) {
try {
- if (AssetType.VFCMT == getValidAssetTypeOrNull(assetType)) {
+ if (AssetType.VFCMT == baseBusinessLogic.getValidAssetTypeOrNull(assetType)) {
ResourceDetailed vfcmt = baseBusinessLogic.getSdcRestClient().changeResourceLifecycleState(userId, uuid, LifecycleOperationType.CERTIFY.name(), "certifying VFCMT", requestId);
return new ResponseEntity<>(vfcmt, HttpStatus.OK);
diff --git a/dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/controller/RuleEditorController.java b/dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/controller/RuleEditorController.java
index 8de8520..d7ddd6f 100644
--- a/dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/controller/RuleEditorController.java
+++ b/dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/controller/RuleEditorController.java
@@ -14,8 +14,6 @@ import org.springframework.web.bind.annotation.*;
@RequestMapping("/rule-editor")
public class RuleEditorController extends BaseController {
- private static final String EXCEPTION = "Exception {}";
-
@Autowired
private RuleEditorBusinessLogic ruleEditorBusinessLogic;
@@ -70,7 +68,7 @@ public class RuleEditorController extends BaseController {
* @param configParam - the name of the DCAE Component configuration property the rule is linked to
* @return json representing the rule editor UI
*/
- @RequestMapping(value = "/rule/{vfcmtUuid}/{dcaeCompLabel}/{nid}/{configParam}", method = {RequestMethod.GET}, produces = "application/json")
+ @RequestMapping(value = "/rule/{vfcmtUuid}/{dcaeCompLabel}/{nid}/{configParam:.*}", method = {RequestMethod.GET}, produces = "application/json")
public ResponseEntity getRules(
@PathVariable("vfcmtUuid") String vfcmtUuid,
@PathVariable("dcaeCompLabel") String dcaeCompLabel,
@@ -119,9 +117,8 @@ public class RuleEditorController extends BaseController {
* 1. That the user is able to edit the VFCMT
* 2. That the cdump holds a dcae component with such nid (to avoid orphan rules)
* 3. Check that the fetched VFCMT is actually a VFCMT and not a regular VF
- * @throws Exception
*/
- @RequestMapping(value = "/rule/translate/{vfcmtUuid}/{dcaeCompLabel}/{nid}/{configParam}", method = {RequestMethod.GET}, produces = "application/json")
+ @RequestMapping(value = "/rule/translate/{vfcmtUuid}/{dcaeCompLabel}/{nid}/{configParam:.*}", method = {RequestMethod.GET}, produces = "application/json")
public ResponseEntity translateRules(@PathVariable("vfcmtUuid") String vfcmtUuid, @ModelAttribute("requestId") String requestId,
@PathVariable("dcaeCompLabel") String dcaeCompLabel,
@PathVariable("nid") String nid,
@@ -140,6 +137,4 @@ public class RuleEditorController extends BaseController {
debugLogger.log(LogLevel.DEBUG, this.getClass().getName(), "Starting getExistingRuleTargets ", vfcmtUuid);
return ruleEditorBusinessLogic.getExistingRuleTargets(vfcmtUuid, requestId, dcaeCompLabel, nid);
}
-
-
}
diff --git a/dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/controller/VfcmtController.java b/dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/controller/VfcmtController.java
index 7d64dad..4fbce49 100644
--- a/dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/controller/VfcmtController.java
+++ b/dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/controller/VfcmtController.java
@@ -23,7 +23,6 @@ import java.util.List;
@CrossOrigin
public class VfcmtController extends BaseController{
-
@Autowired
private VfcmtBusinessLogic vfcmtBusinessLogic;
@Autowired
@@ -33,8 +32,6 @@ public class VfcmtController extends BaseController{
private static final String BASE_MONITORING_TEMPLATE = "Base Monitoring Template";
private static final String MONITORING_TEMPLATE = "Monitoring Template";
-
-
/***
* Get one resource information
* @param theResourceId retrieved resource id
diff --git a/dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/impl/BaseBusinessLogic.java b/dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/impl/BaseBusinessLogic.java
index bfec7ed..6779257 100644
--- a/dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/impl/BaseBusinessLogic.java
+++ b/dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/impl/BaseBusinessLogic.java
@@ -11,6 +11,7 @@ import org.onap.sdc.dcae.composition.restmodels.CreateMcResponse;
import org.onap.sdc.dcae.composition.restmodels.VfcmtData;
import org.onap.sdc.dcae.composition.restmodels.sdc.*;
import org.onap.sdc.dcae.composition.util.DcaeBeConstants;
+import org.onap.sdc.dcae.composition.util.SystemProperties;
import org.onap.sdc.dcae.enums.AssetType;
import org.onap.sdc.dcae.enums.LifecycleOperationType;
import org.onap.sdc.dcae.errormng.ActionStatus;
@@ -21,7 +22,6 @@ import org.onap.sdc.dcae.utils.Normalizers;
import org.onap.sdc.dcae.utils.SdcRestClientUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
-import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.util.Base64Utils;
@@ -29,6 +29,10 @@ import java.io.IOException;
@Component
public class BaseBusinessLogic {
+
+ @Autowired
+ protected SystemProperties systemProperties;
+
@Autowired
protected ISdcClient sdcRestClient;
@@ -39,6 +43,10 @@ public class BaseBusinessLogic {
return sdcRestClient;
}
+ public SystemProperties getSystemProperties() {
+ return systemProperties;
+ }
+
void setSdcRestClient(ISdcClient sdcRestClient) {
this.sdcRestClient = sdcRestClient;
}
@@ -85,7 +93,7 @@ public class BaseBusinessLogic {
return new CreateMcResponse(vfcmt, new ObjectMapper().readValue(cdumpPayload, Object.class));
}
- public Artifact fetchCdump(ResourceDetailed vfcmt, String requestId) {
+ Artifact fetchCdump(ResourceDetailed vfcmt, String requestId) {
Artifact cdumpArtifactData = findCdumpArtifactData(vfcmt);
if (null != cdumpArtifactData) {
String cdumpPayload = sdcRestClient.getResourceArtifact(vfcmt.getUuid(), cdumpArtifactData.getArtifactUUID(), requestId);
@@ -110,22 +118,19 @@ public class BaseBusinessLogic {
.filter(p -> Normalizers.normalizeComponentInstanceName(vfiName).equals(Normalizers.normalizeComponentInstanceName(p.getResourceInstanceName()))).findAny().orElse(null);
}
- public String extractFlowTypeFromCdump(String cdump) {
+ String extractFlowTypeFromCdump(String cdump) {
return StringUtils.substringBetween(cdump,"\"flowType\":\"","\"");
}
- // TODO - reuse
-
- ResourceDetailed checkinVfcmt(String userId, String uuid, String requestId) {
+ public ResourceDetailed checkinVfcmt(String userId, String uuid, String requestId) {
return getSdcRestClient().changeResourceLifecycleState(userId, uuid, LifecycleOperationType.CHECKIN.name(), "checking in vfcmt" + uuid, requestId);
}
- ResourceDetailed checkoutVfcmt(String userId, String uuid, String requestId) {
+ public ResourceDetailed checkoutVfcmt(String userId, String uuid, String requestId) {
return getSdcRestClient().changeResourceLifecycleState(userId, uuid, LifecycleOperationType.CHECKOUT.name(), null, requestId);
}
- // TODO - remove from BaseController
- void checkUserIfResourceCheckedOut(String userId, Asset asset) {
+ public void checkUserIfResourceCheckedOut(String userId, Asset asset) {
if (DcaeBeConstants.LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT == DcaeBeConstants.LifecycleStateEnum.findState(asset.getLifecycleState())) {
String lastUpdaterUserId = asset.getLastUpdaterUserId();
if (lastUpdaterUserId != null && !lastUpdaterUserId.equals(userId)) {
@@ -136,18 +141,18 @@ public class BaseBusinessLogic {
}
}
- boolean isNeedToCheckOut(String lifecycleState) {
+ public boolean isNeedToCheckOut(String lifecycleState) {
return DcaeBeConstants.LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT != DcaeBeConstants.LifecycleStateEnum.findState(lifecycleState);
}
- void checkVfcmtType(ResourceDetailed vfcmt) {
+ public void checkVfcmtType(ResourceDetailed vfcmt) {
if (AssetType.VFCMT != getValidAssetTypeOrNull(vfcmt.getResourceType()) || !"Template".equals(vfcmt.getCategory())) {
ResponseFormat responseFormat = ErrConfMgr.INSTANCE.getResponseFormat(ActionStatus.RESOURCE_NOT_VFCMT_ERROR, null, vfcmt.getUuid());
throw new DcaeException(HttpStatus.BAD_REQUEST, responseFormat.getRequestError());
}
}
- AssetType getValidAssetTypeOrNull(String type) {
+ public AssetType getValidAssetTypeOrNull(String type) {
try {
return AssetType.getAssetTypeByName(type);
} catch (IllegalArgumentException e) {
@@ -156,9 +161,4 @@ public class BaseBusinessLogic {
}
}
- ResponseEntity handleException(Exception e, ErrConfMgr.ApiType apiType, String... variables){
- errLogger.log(LogLevel.ERROR, this.getClass().getName(), e.getMessage());
- return ErrConfMgr.INSTANCE.handleException(e, apiType, variables);
- }
-
}
diff --git a/dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/impl/BlueprintBusinessLogic.java b/dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/impl/BlueprintBusinessLogic.java
index 0ccb6d8..7a6f9a7 100644
--- a/dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/impl/BlueprintBusinessLogic.java
+++ b/dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/impl/BlueprintBusinessLogic.java
@@ -10,7 +10,6 @@ import org.onap.sdc.dcae.composition.restmodels.VfcmtData;
import org.onap.sdc.dcae.composition.restmodels.sdc.Artifact;
import org.onap.sdc.dcae.composition.restmodels.sdc.ResourceDetailed;
import org.onap.sdc.dcae.composition.util.DcaeBeConstants;
-import org.onap.sdc.dcae.composition.util.SystemProperties;
import org.onap.sdc.dcae.errormng.ActionStatus;
import org.onap.sdc.dcae.errormng.ErrConfMgr;
import org.springframework.beans.factory.annotation.Autowired;
@@ -23,15 +22,12 @@ import java.io.StringReader;
import java.net.URI;
@Component
-public class BlueprintBusinessLogic extends BaseBusinessLogic {
+public class BlueprintBusinessLogic extends CompositionBusinessLogic {
@Autowired
private Blueprinter blueprinter;
@Autowired
private ASDC asdc;
- @Autowired
- private SystemProperties systemProperties;
- @Autowired private CompositionBusinessLogic compositionBusinessLogic;
@PostConstruct
@@ -41,6 +37,7 @@ public class BlueprintBusinessLogic extends BaseBusinessLogic {
debugLogger.log(LogLevel.DEBUG, this.getClass().getName(), "SDC uri: {}", sdcUri);
}
+
public ResponseEntity generateAndSaveBlueprint(String userId, String context, String vfcmtUuid, String serviceUuid, String vfiName, String flowType, String requestId) {
try {
// prepare - fetch vfcmt and cdump
@@ -69,7 +66,7 @@ public class BlueprintBusinessLogic extends BaseBusinessLogic {
}
VfcmtData vfcmtData = new VfcmtData(vfcmt, vfiName, flowTypeFromCdump, serviceUuid);
- Artifact blueprintArtifactResult = compositionBusinessLogic.submitComposition(userId, context, vfcmtData, resultBlueprintCreation, requestId);
+ Artifact blueprintArtifactResult = submitComposition(userId, context, vfcmtData, resultBlueprintCreation, requestId);
if (null == blueprintArtifactResult) {
return ErrConfMgr.INSTANCE.buildErrorResponse(ActionStatus.SUBMIT_BLUEPRINT_ERROR);
}
@@ -78,7 +75,8 @@ public class BlueprintBusinessLogic extends BaseBusinessLogic {
response.setSuccessResponse("Blueprint build complete \n. Blueprint=" + blueprintArtifactResult.getArtifactName());
return new ResponseEntity<>(response, HttpStatus.OK);
} catch (Exception e) {
- return handleException(e, ErrConfMgr.ApiType.SUBMIT_BLUEPRINT);
+ errLogger.log(LogLevel.ERROR, this.getClass().getName(), e.getMessage());
+ return ErrConfMgr.INSTANCE.handleException(e, ErrConfMgr.ApiType.SUBMIT_BLUEPRINT);
}
}
diff --git a/dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/impl/CompositionBusinessLogic.java b/dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/impl/CompositionBusinessLogic.java
index e81ffe0..a3c68f6 100644
--- a/dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/impl/CompositionBusinessLogic.java
+++ b/dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/impl/CompositionBusinessLogic.java
@@ -31,6 +31,13 @@ public class CompositionBusinessLogic extends BaseBusinessLogic {
private static final String CREATE_DESC = "creating new artifact blueprint on the service vfi";
private static final String UPDATE_DESC = "updating artifact blueprint on the service vfi";
+ //canvas cdump as simple string
+ public Artifact getComposition(String vfcmtUuid, String requestId) {
+ ResourceDetailed vfcmt = sdcRestClient.getResource(vfcmtUuid, requestId);
+ return fetchCdump(vfcmt, requestId);
+ }
+
+ //cdump and vfcmt for monitoring configuration
public CreateMcResponse getDataAndComposition(String vfcmtUuid, String requestId) throws IOException {
ResourceDetailed vfcmt = sdcRestClient.getResource(vfcmtUuid, requestId);
Artifact composition = fetchCdump(vfcmt, requestId);
@@ -73,7 +80,7 @@ public class CompositionBusinessLogic extends BaseBusinessLogic {
}
}
- public Artifact submitComposition(String userId, String context, VfcmtData vfcmtData, String resultBlueprintCreation, String requestId) throws JsonProcessingException {
+ Artifact submitComposition(String userId, String context, VfcmtData vfcmtData, String resultBlueprintCreation, String requestId) throws JsonProcessingException {
// get service / find vfi
ServiceDetailed service = sdcRestClient.getAssetMetadata(context, vfcmtData.getServiceUuid(), requestId);
diff --git a/dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/impl/CompositionCatalogBusinessLogic.java b/dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/impl/CompositionCatalogBusinessLogic.java
new file mode 100644
index 0000000..ff596b5
--- /dev/null
+++ b/dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/impl/CompositionCatalogBusinessLogic.java
@@ -0,0 +1,205 @@
+package org.onap.sdc.dcae.composition.impl;
+
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.onap.sdc.common.onaplog.Enums.LogLevel;
+import org.onap.sdc.common.onaplog.OnapLoggerError;
+import org.onap.sdc.dcae.catalog.Catalog;
+import org.onap.sdc.dcae.catalog.engine.*;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+import org.springframework.web.context.request.async.DeferredResult;
+
+@Component
+public class CompositionCatalogBusinessLogic {
+
+ @Autowired
+ private CatalogController catalogController;
+
+ protected OnapLoggerError errLogger = OnapLoggerError.getInstance();
+
+ public DeferredResult<CatalogResponse> getItems(ItemsRequest theRequest) {
+
+ final ItemsRequest request = (theRequest == null) ? ItemsRequest.EMPTY_REQUEST : theRequest;
+
+ Catalog catalog = catalogController.getCatalog(request.getCatalog());
+ DeferredResult<CatalogResponse> result = new DeferredResult<>(request.getTimeout());
+
+ catalog.rootsByLabel(request.getStartingLabel()).setHandler(catalogController.new CatalogHandler<Catalog.Folders>(request, result) {
+ public CatalogResponse handleData(Catalog.Folders theFolders) {
+ JSONArray ja = new JSONArray();
+ if (theFolders != null) {
+ for (Catalog.Folder folder : theFolders) {
+ ja.put(catalogController.patchData(catalog, folder.data()));
+ }
+ }
+ CatalogResponse response = new CatalogResponse(this.request);
+ try {
+ response.data().put("elements", ja);
+ } catch (JSONException e) {
+ errLogger.log(LogLevel.ERROR, this.getClass().getName(), "JSONException putting json elements to response {}", e);
+ }
+ return response;
+ }
+ });
+ return result;
+ }
+
+ public DeferredResult<CatalogResponse> getItemById(ItemsRequest theRequest, String theItemId) {
+
+ final ItemsRequest request = (theRequest == null) ? ItemsRequest.EMPTY_REQUEST : theRequest;
+
+ Catalog catalog = catalogController.getCatalog(request.getCatalog());
+ DeferredResult<CatalogResponse> result = new DeferredResult<>(request.getTimeout());
+
+ catalog.folder(theItemId).withParts().withPartAnnotations().withItems().withItemAnnotations().withItemModels().execute().setHandler(new FolderHandler(catalog, request, result));
+ return result;
+ }
+
+ public DeferredResult getModelById(ElementRequest theRequest, String theItemId) {
+ final ElementRequest request = (theRequest == null) ? ElementRequest.EMPTY_REQUEST : theRequest;
+
+ Catalog catalog = catalogController.getCatalog(request.getCatalog());
+ DeferredResult<CatalogResponse> result = new DeferredResult<>(request.getTimeout());
+
+// try {
+ catalog.item(theItemId).withModels().execute().setHandler(new ItemHandler(catalog, request, result));
+// } catch (IllegalArgumentException e) {
+// errLogger.log(LogLevel.ERROR, this.getClass().getName(), "Error fetching catalog model with id {}. Message: {}", theItemId, e);
+// result.setErrorResult(new CatalogError(request, "Catalog API failed", e));
+// }
+ return result;
+ }
+
+ public DeferredResult<CatalogResponse> getTypeInfo(ElementRequest theRequest, String theItemId, String theTypeName) {
+ final ElementRequest request = (theRequest == null) ? ElementRequest.EMPTY_REQUEST : theRequest;
+
+ Catalog catalog = catalogController.getCatalog(request.getCatalog());
+ DeferredResult<CatalogResponse> result = new DeferredResult<>(request.getTimeout());
+
+ catalog.type(theItemId, theTypeName).withHierarchy().withCapabilities().withRequirements().execute().setHandler(catalogController.new CatalogHandler<Catalog.Type>(request, result) {
+ public CatalogResponse handleData(Catalog.Type theType) {
+ CatalogResponse response = new CatalogResponse(this.request);
+ if (theType != null) {
+ try {
+ response.data().put("type", catalogController.patchData(catalog, theType.data()));
+ } catch (JSONException e) {
+ errLogger.log(LogLevel.ERROR, this.getClass().getName(), "Exception processing catalog {}", e);
+ }
+ }
+ return response;
+ }
+ });
+ return result;
+ }
+
+ /// Nested Catalog Data Handlers ///
+
+ private class FolderHandler extends CatalogController.CatalogHandler<Catalog.Folder> {
+
+ private Catalog catalog;
+
+ private FolderHandler(Catalog catalog, ItemsRequest request, DeferredResult result) {
+ catalogController.super(request, result);
+ this.catalog = catalog;
+ }
+
+ private void patchCatalogData(Catalog.Elements folders, Catalog catalog) {
+ if (folders != null) {
+ folders.forEach(folder -> {
+ catalogController.patchData(catalog, ((Catalog.Element) folder).data());
+ // lots of ephemere proxies created here ..
+ Catalog.Elements annotations = ((Catalog.Element) folder).elements("annotations", Catalog.Annotations.class);
+ if (annotations != null) {
+ annotations.forEach(a -> catalogController.patchData(catalog, ((Catalog.Annotation) a).data()));
+ }
+ });
+ }
+ }
+
+ public CatalogResponse handleData(Catalog.Folder theFolder) {
+ CatalogResponse response = new CatalogResponse(this.request);
+ if (theFolder == null) {
+ return response;
+ }
+ try {
+ Catalog.Elements folders = theFolder.elements("parts", Catalog.Folders.class);
+ patchCatalogData(folders, catalog);
+ Catalog.Elements items = theFolder.elements("items", Catalog.Items.class);
+ patchCatalogData(items, catalog);
+ } catch (Exception x) {
+ errLogger.log(LogLevel.ERROR, this.getClass().getName(), "Exception processing catalog {}", x);
+ return new CatalogError(this.request, "", x);
+ }
+ try {
+ response.data().put("element", theFolder.data());
+ } catch (JSONException e) {
+ errLogger.log(LogLevel.ERROR, this.getClass().getName(), "JSONException putting element to response {}", e);
+ }
+ return response;
+ }
+ }
+
+ private class ItemHandler extends CatalogController.CatalogHandler<Catalog.Item> {
+
+ private Catalog catalog;
+
+ private ItemHandler(Catalog catalog, ElementRequest request, DeferredResult result) {
+ catalogController.super(request, result);
+ this.catalog = catalog;
+ }
+
+ public CatalogResponse handleData(Catalog.Item theItem) {
+ if (theItem == null) {
+ return new CatalogError(this.request, "No such item");
+ }
+ Catalog.Templates models;
+ try {
+ models = (Catalog.Templates) theItem.elements("models", Catalog.Templates.class);
+ } catch (Exception x) {
+ return new CatalogError(this.request, "Failed to decode templates from result", x);
+ }
+ if (models == null || models.isEmpty()) {
+ return new CatalogError(this.request, "Item has no models");
+ }
+ if (models.size() > 1) {
+ return new CatalogError(this.request, "Item has more than one model !?");
+ }
+ try {
+ catalog.template(models.get(0).id()).withInputs().withOutputs().withNodes().withNodeProperties().withNodePropertiesAssignments().withNodeRequirements().withNodeCapabilities().withNodeCapabilityProperties()
+ .withNodeCapabilityPropertyAssignments().withPolicies().withPolicyProperties().withPolicyPropertiesAssignments().execute().setHandler(new TemplateHandler(this.catalog, this.request, this.result));
+ } catch (Exception e) {
+ errLogger.log(LogLevel.ERROR, this.getClass().getName(), "Exception caught during Catalog Item Handler: {}", e);
+ }
+ return null;
+ }
+ }
+
+ private class TemplateHandler extends CatalogController.CatalogHandler<Catalog.Template> {
+
+ private Catalog catalog;
+
+ private TemplateHandler(Catalog catalog, CatalogRequest request, DeferredResult result) {
+ catalogController.super(request, result);
+ this.catalog = catalog;
+ }
+
+ public CatalogResponse handleData(Catalog.Template theTemplate) {
+ CatalogResponse response = new CatalogResponse(this.request);
+ if (theTemplate != null) {
+ try {
+ response.data().put("model", catalogController.patchData(catalog, theTemplate.data()));
+ } catch (JSONException e) {
+ errLogger.log(LogLevel.ERROR, this.getClass().getName(), "JSONException putting model to response {}", e);
+ }
+ }
+ return response;
+ }
+ }
+}
+
+
+
+
+
+
diff --git a/dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/impl/ReferenceBusinessLogic.java b/dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/impl/ReferenceBusinessLogic.java
index 1396cc9..9c950b6 100644
--- a/dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/impl/ReferenceBusinessLogic.java
+++ b/dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/impl/ReferenceBusinessLogic.java
@@ -34,7 +34,7 @@ public class ReferenceBusinessLogic extends BaseBusinessLogic {
.ifPresent(artifact -> sdcRestClient.deleteInstanceArtifact(userId, context, serviceUuid, normalizedVfiName, artifact.getArtifactUUID(), requestId));
}
} catch (Exception e) {
- debugLogger.log(LogLevel.DEBUG, this.getClass().getName(),"Failed to delete blueprint with serviceUuid {}, vfcmtUuid . message: {} ", serviceUuid, vfcmtUuid, e);
+ debugLogger.log(LogLevel.DEBUG, this.getClass().getName(),"Failed to delete blueprint with serviceUuid {}, vfcmtUuid {}, message: {} ", serviceUuid, vfcmtUuid, e);
return ErrConfMgr.INSTANCE.buildErrorResponse(ActionStatus.DELETE_BLUEPRINT_FAILED, e.getMessage());
}
return new ResponseEntity<>(HttpStatus.OK);
diff --git a/dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/impl/RuleEditorBusinessLogic.java b/dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/impl/RuleEditorBusinessLogic.java
index d17a6bf..298ffac 100644
--- a/dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/impl/RuleEditorBusinessLogic.java
+++ b/dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/impl/RuleEditorBusinessLogic.java
@@ -29,7 +29,6 @@ import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.util.Base64Utils;
import org.springframework.util.CollectionUtils;
-import org.springframework.web.bind.annotation.*;
import java.util.*;
import java.util.stream.Collectors;
diff --git a/dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/impl/ServiceBusinessLogic.java b/dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/impl/ServiceBusinessLogic.java
index d04c67a..8dbe2e9 100644
--- a/dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/impl/ServiceBusinessLogic.java
+++ b/dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/impl/ServiceBusinessLogic.java
@@ -1,29 +1,29 @@
package org.onap.sdc.dcae.composition.impl;
- import org.onap.sdc.common.onaplog.Enums.LogLevel;
- import org.onap.sdc.dcae.composition.restmodels.AttachVFCMTServiceRequest;
- import org.onap.sdc.dcae.composition.restmodels.DcaeMinimizedService;
- import org.onap.sdc.dcae.composition.restmodels.MessageResponse;
- import org.onap.sdc.dcae.composition.restmodels.sdc.*;
- import org.onap.sdc.dcae.composition.util.DcaeBeConstants;
- import org.onap.sdc.dcae.enums.ArtifactType;
- import org.onap.sdc.dcae.enums.LifecycleOperationType;
- import org.onap.sdc.dcae.errormng.ActionStatus;
- import org.onap.sdc.dcae.errormng.DcaeException;
- import org.onap.sdc.dcae.errormng.ErrConfMgr;
- import org.onap.sdc.dcae.errormng.ResponseFormat;
- import org.onap.sdc.dcae.utils.SdcRestClientUtils;
- import org.springframework.http.HttpStatus;
- import org.springframework.http.ResponseEntity;
- import org.springframework.stereotype.Component;
- import org.springframework.util.Base64Utils;
- import org.springframework.util.CollectionUtils;
-
- import java.util.ArrayList;
- import java.util.Comparator;
- import java.util.LinkedHashMap;
- import java.util.List;
- import java.util.stream.Collectors;
+import org.onap.sdc.common.onaplog.Enums.LogLevel;
+import org.onap.sdc.dcae.composition.restmodels.AttachVFCMTServiceRequest;
+import org.onap.sdc.dcae.composition.restmodels.DcaeMinimizedService;
+import org.onap.sdc.dcae.composition.restmodels.MessageResponse;
+import org.onap.sdc.dcae.composition.restmodels.sdc.*;
+import org.onap.sdc.dcae.composition.util.DcaeBeConstants;
+import org.onap.sdc.dcae.enums.ArtifactType;
+import org.onap.sdc.dcae.enums.LifecycleOperationType;
+import org.onap.sdc.dcae.errormng.ActionStatus;
+import org.onap.sdc.dcae.errormng.DcaeException;
+import org.onap.sdc.dcae.errormng.ErrConfMgr;
+import org.onap.sdc.dcae.errormng.ResponseFormat;
+import org.onap.sdc.dcae.utils.SdcRestClientUtils;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.stereotype.Component;
+import org.springframework.util.Base64Utils;
+import org.springframework.util.CollectionUtils;
+
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.stream.Collectors;
@Component
public class ServiceBusinessLogic extends BaseBusinessLogic {
diff --git a/dcaedt_be/src/main/java/org/onap/sdc/dcae/rule/editor/validators/RuleValidator.java b/dcaedt_be/src/main/java/org/onap/sdc/dcae/rule/editor/validators/RuleValidator.java
index e03ca8a..33e1b33 100644
--- a/dcaedt_be/src/main/java/org/onap/sdc/dcae/rule/editor/validators/RuleValidator.java
+++ b/dcaedt_be/src/main/java/org/onap/sdc/dcae/rule/editor/validators/RuleValidator.java
@@ -20,11 +20,11 @@ public class RuleValidator implements IRuleElementValidator<Rule> {
private RuleValidator(){}
-
public boolean validate(Rule rule, List<ResponseFormat> errors) {
boolean valid = true;
- if(rule.isConditionalRule())
+ if(rule.isConditionalRule()) {
valid = getConditionValidator(rule.getCondition()).validate(rule.getCondition(), errors);
+ }
if(!ValidationUtils.validateNotEmpty(rule.getDescription())) {
valid = false;
errors.add(ErrConfMgr.INSTANCE.getResponseFormat(ActionStatus.MISSING_RULE_DESCRIPTION, null, null));