diff options
author | Michael Lando <ml636r@att.com> | 2017-02-19 12:35:04 +0200 |
---|---|---|
committer | Michael Lando <ml636r@att.com> | 2017-02-19 12:35:04 +0200 |
commit | f5f13c4f6b6fe3b4d98e349dfd7db59339803436 (patch) | |
tree | 72caffc93fab394ffa3b761505775331f1c559b9 /openecomp-be/lib/openecomp-sdc-action-lib | |
parent | 451a3400b76511393c62a444f588a4ed15f4a549 (diff) |
push addional code
Change-Id: Ia427bb3460cda3a896f8faced2de69eaf3807b74
Signed-off-by: Michael Lando <ml636r@att.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-action-lib')
31 files changed, 3083 insertions, 0 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/pom.xml b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/pom.xml new file mode 100644 index 0000000000..d0512a480d --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/pom.xml @@ -0,0 +1,45 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.openecomp.sdc</groupId> + <artifactId>openecomp-sdc-action-lib</artifactId> + <version>1.0.0-SNAPSHOT</version> + </parent> + + <artifactId>openecomp-sdc-action-api</artifactId> + + + <dependencies> + <dependency> + <groupId>org.openecomp.core</groupId> + <artifactId>openecomp-core-lib</artifactId> + <type>pom</type> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.openecomp.core</groupId> + <artifactId>openecomp-facade-core</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.openecomp.core</groupId> + <artifactId>openecomp-nosqldb-core</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.openecomp.sdc</groupId> + <artifactId>openecomp-sdc-versioning-api</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>com.fasterxml.jackson.core</groupId> + <artifactId>jackson-annotations</artifactId> + <version>2.7.4</version> + </dependency> + </dependencies> + +</project>
\ No newline at end of file diff --git a/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/ActionConstants.java b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/ActionConstants.java new file mode 100644 index 0000000000..625ce7efe8 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/ActionConstants.java @@ -0,0 +1,104 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.action; + +public class ActionConstants { + + // + public static final long MAX_ACTION_ARTIFACT_SIZE = 20 * 1024 * 1024; //20 MB + //REST layer constants + public static final String X_ECOMP_INSTANCE_ID_HEADER_PARAM = "X-ECOMP-InstanceID"; + public static final String X_ECOMP_REQUEST_ID_HEADER_PARAM = "X-ECOMP-RequestID"; + public static final String WWW_AUTHENTICATE_HEADER_PARAM = "WWW-Authenticate"; + + public static final String ACTION_REQUEST_PARAM_NAME = "name"; + public static final String ACTION_REQUEST_PARAM_END_POINT_URI = "endpointUri"; + public static final String SUPPORTED_MODELS_VERSION_ID = "versionId"; + public static final String SUPPORTED_COMPONENTS_ID = "Id"; + public static final String ACTION_REQUEST_PARAM_SUPPORTED_MODELS = SUPPORTED_MODELS_VERSION_ID + + " in supportedModels"; + public static final String ACTION_REQUEST_PARAM_SUPPORTED_COMPONENTS = + SUPPORTED_COMPONENTS_ID + " in supportedComponents"; + + public static final String REQUEST_EMPTY_BODY = "{}"; + public static final String REQUEST_TYPE_CREATE_ACTION = "REQUEST_CREATE_ACTION"; + public static final String REQUEST_TYPE_UPDATE_ACTION = "REQUEST_UPDATE_ACTION"; + public static final String REQUEST_TYPE_VERSION_ACTION = "REQUEST_VERSION_ACTION"; + + //DAO layer constants + public static final String ACTION_VERSIONABLE_TYPE = "Action"; + + //Manager constants + public static final String UNIQUE_ID = "actionUuId"; + public static final String VERSION = "version"; + public static final String INVARIANTUUID = "actionInvariantUuId"; + public static final String STATUS = "status"; + public static final String ARTIFACTS = "artifacts"; + public static final String TIMESTAMP = "timeStamp"; + public static final String UPDATED_BY = "updatedBy"; + public static final String ARTIFACT_NAME = "artifactName"; + public static final String ARTIFACT_FILE = "Artifact to be uploaded"; + + // Status + public static final String UNDO_CHECKOUT_RESPONSE_TEXT = + "Changes to the Action object successfully reverted back."; + + //GET Request Filter Types + public static final String FILTER_TYPE_VENDOR = "VENDOR"; + public static final String FILTER_TYPE_CATEGORY = "CATEGORY"; + public static final String FILTER_TYPE_NAME = "NAME"; + public static final String FILTER_TYPE_MODEL = "MODEL"; + public static final String FILTER_TYPE_ECOMP_COMPONENT = "ECOMP_COMPONENT"; + public static final String FILTER_TYPE_NONE = "NONE"; + + public static final String ARTIFACT_METADATA_ATTR_UUID = "ARTIFACT_UUID"; + public static final String ARTIFACT_METADATA_ATTR_NAME = "ARTIFACT_NAME"; + + public static final String REQUEST_ID = "uuid"; + public static final String SERVICE_INSTANCE_ID = "serviceInstanceID"; + public static final String PARTNER_NAME = "userId"; + public static final String SERVICE_NAME = "ServiceName"; + public static final String INSTANCE_UUID = "InstanceUUID"; + public static final String REMOTE_HOST = "RemoteHost"; + public static final String CLIENT_IP = "ClientIP"; + public static final String CATEGORY_LOG_LEVEL = "level"; + public static final String STATUS_CODE = "StatusCode"; + public static final String RESPONSE_CODE = "ResponseCode"; + public static final String RESPONSE_DESCRIPTION = "ResponseDescription"; + public static final String ELAPSED_TIME = "ElapsedTime"; + public static final String BEGIN_TIMESTAMP = "BeginTimestamp"; + public static final String TARGET_SERVICE_NAME = "TargetServiceName"; + public static final String TARGET_ENTITY = "TargetEntity"; + public static final String TARGET_ENTITY_API = "API"; + public static final String TARGET_ENTITY_DB = "DB"; + public static final String END_TIMESTAMP = "EndTimestamp"; + public static final String ERROR_CATEGORY = "ErrorCategory"; + public static final String ERROR_CODE = "ErrorCode"; + public static final String ERROR_DESCRIPTION = "ErrorDescription"; + public static final String MDC_ASDC_INSTANCE_UUID = "ASDC"; + public static final String SERVICE_METRIC_BEGIN_TIMESTAMP = "SERVICE-METRIC-BEGIN-TIMESTAMP"; + public static final String LOCAL_ADDR = "localAddr"; //map ServerIPAddress from loggingfilter + public static final String BE_FQDN = "beFqdn"; //map ServerFQDN from logging filter + + public final class UniqueValues { + public static final String ACTION_NAME = "Action name"; + } +} diff --git a/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/dao/ActionArtifactDao.java b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/dao/ActionArtifactDao.java new file mode 100644 index 0000000000..a120645512 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/dao/ActionArtifactDao.java @@ -0,0 +1,34 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.action.dao; + +import org.openecomp.core.dao.BaseDao; +import org.openecomp.sdc.action.dao.types.ActionArtifactEntity; +import org.openecomp.sdc.action.types.ActionArtifact; + +public interface ActionArtifactDao extends BaseDao<ActionArtifactEntity> { + + void uploadArtifact(ActionArtifact data); + + ActionArtifact downloadArtifact(int effectiveVersion, String artifactUuId); + + void updateArtifact(ActionArtifact data); +} diff --git a/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/dao/ActionArtifactDaoFactory.java b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/dao/ActionArtifactDaoFactory.java new file mode 100644 index 0000000000..f0936976ba --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/dao/ActionArtifactDaoFactory.java @@ -0,0 +1,31 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.action.dao; + +import org.openecomp.core.factory.api.AbstractComponentFactory; +import org.openecomp.core.factory.api.AbstractFactory; + +public abstract class ActionArtifactDaoFactory extends AbstractComponentFactory<ActionArtifactDao> { + + public static ActionArtifactDaoFactory getInstance() { + return AbstractFactory.getInstance(ActionArtifactDaoFactory.class); + } +} diff --git a/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/dao/ActionDao.java b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/dao/ActionDao.java new file mode 100644 index 0000000000..01f5014ad4 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/dao/ActionDao.java @@ -0,0 +1,51 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.action.dao; + +import org.openecomp.core.dao.BaseDao; +import org.openecomp.sdc.action.dao.types.ActionEntity; +import org.openecomp.sdc.action.errors.ActionException; +import org.openecomp.sdc.action.types.Action; +import org.openecomp.sdc.action.types.EcompComponent; +import org.openecomp.sdc.versioning.dao.VersionableDao; + +import java.util.List; + +public interface ActionDao extends VersionableDao, BaseDao<ActionEntity> { + + Action createAction(Action actionDto) throws ActionException; + + Action updateAction(Action actionDto) throws ActionException; + + void deleteAction(String actionInvariantUuId) throws ActionException; + + List<Action> getFilteredActions(String filterType, String filterId) throws ActionException; + + Action getActionsByActionUuId(String uniqueId) throws ActionException; + + List<EcompComponent> getEcompComponents() throws ActionException; + + List<Action> getActionsByActionInvariantUuId(String actionInvariantUuId) + throws ActionException; + + Action getLockedAction(String actionInvariantUuId, String user) throws ActionException; + +} diff --git a/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/dao/ActionDaoFactory.java b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/dao/ActionDaoFactory.java new file mode 100644 index 0000000000..d8b0c1889e --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/dao/ActionDaoFactory.java @@ -0,0 +1,31 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.action.dao; + +import org.openecomp.core.factory.api.AbstractComponentFactory; +import org.openecomp.core.factory.api.AbstractFactory; + +public abstract class ActionDaoFactory extends AbstractComponentFactory<ActionDao> { + + public static ActionDaoFactory getInstance() { + return AbstractFactory.getInstance(ActionDaoFactory.class); + } +} diff --git a/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/dao/types/ActionArtifactEntity.java b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/dao/types/ActionArtifactEntity.java new file mode 100644 index 0000000000..7e56a04e1b --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/dao/types/ActionArtifactEntity.java @@ -0,0 +1,89 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.action.dao.types; + +import com.datastax.driver.mapping.annotations.Column; +import com.datastax.driver.mapping.annotations.PartitionKey; +import com.datastax.driver.mapping.annotations.Table; +import org.openecomp.sdc.action.types.ActionArtifact; + +import java.nio.ByteBuffer; + +@Table(keyspace = "dox", name = "action_artifact") +public class ActionArtifactEntity { + + @PartitionKey + @Column(name = "artifactuuid") + private String artifactUuId; + + @PartitionKey(value = 1) + @Column(name = "effective_version") + private int effectiveVersion; + + @Column(name = "artifact") + private ByteBuffer artifact; + + public ActionArtifactEntity() { + //Default constructor implementation + } + + public ActionArtifactEntity(String artifactUuId, int effectiveVersion) { + this.artifactUuId = artifactUuId; + this.effectiveVersion = effectiveVersion; + } + + public String getArtifactUuId() { + return artifactUuId; + } + + public void setArtifactUuId(String artifactUuId) { + this.artifactUuId = artifactUuId; + } + + public int getEffectiveVersion() { + return effectiveVersion; + } + + public void setEffectiveVersion(int effectiveVersion) { + this.effectiveVersion = effectiveVersion; + } + + public ByteBuffer getArtifact() { + return artifact; + } + + public void setArtifact(ByteBuffer artifact) { + this.artifact = artifact; + } + + /** + * To dto action artifact. + * + * @return the action artifact + */ + public ActionArtifact toDto() { + ActionArtifact destination = new ActionArtifact(); + destination.setArtifactUuId(this.getArtifactUuId()); + destination.setEffectiveVersion(this.getEffectiveVersion()); + destination.setArtifact(this.getArtifact().array()); + return destination; + } +} diff --git a/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/dao/types/ActionEntity.java b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/dao/types/ActionEntity.java new file mode 100644 index 0000000000..9aa9e8d375 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/dao/types/ActionEntity.java @@ -0,0 +1,224 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.action.dao.types; + +import com.datastax.driver.mapping.annotations.Column; +import com.datastax.driver.mapping.annotations.Frozen; +import com.datastax.driver.mapping.annotations.PartitionKey; +import com.datastax.driver.mapping.annotations.Table; +import org.openecomp.core.utilities.json.JsonUtil; +import org.openecomp.sdc.action.types.Action; +import org.openecomp.sdc.versioning.dao.types.Version; + + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.stream.Collectors; + +@Table(keyspace = "dox", name = "Action") +public class ActionEntity { + + @Column(name = "actionUUID") + private String actionUuId; + @PartitionKey(value = 0) + @Column(name = "actionInvariantUUID") + private String actionInvariantUuId; + @PartitionKey(value = 1) + @Frozen + @Column(name = "version") + private Version version; + @Column(name = "status") + private String status; + @Column(name = "name") + private String name; + @Column(name = "vendor_list") + private List<String> vendorList; + @Column(name = "category_list") + private List<String> categoryList; + @Column(name = "timestamp") + private Date timestamp; + @Column(name = "user") + private String user; + @Column(name = "supportedModels") + private List<String> supportedModels; + @Column(name = "supportedComponents") + private List<String> supportedComponents; + @Column(name = "data") + private String data; + + public ActionEntity() { + } + + public ActionEntity(String actionInvariantUuId, Version version) { + this.actionInvariantUuId = actionInvariantUuId; + this.version = version; + } + + public String getActionUuId() { + return actionUuId; + } + + public void setActionUuId(String actionUuId) { + this.actionUuId = actionUuId; + } + + public String getActionInvariantUuId() { + return actionInvariantUuId; + } + + public void setActionInvariantUuId(String actionInvariantUuId) { + this.actionInvariantUuId = actionInvariantUuId; + } + + public Version getVersion() { + return version; + } + + public void setVersion(Version version) { + this.version = version; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public List<String> getVendorList() { + return vendorList; + } + + /** + * Sets vendor list. + * + * @param vendorList the vendor list + */ + public void setVendorList(List<String> vendorList) { + if (vendorList != null && !vendorList.isEmpty()) { + List<String> lowerCaseVendorList = new ArrayList<>(); + lowerCaseVendorList + .addAll(vendorList.stream().map(String::toLowerCase).collect(Collectors.toList())); + this.vendorList = lowerCaseVendorList; + } else { + this.vendorList = vendorList; + } + } + + public List<String> getCategoryList() { + return categoryList; + } + + /** + * Sets category list. + * + * @param categoryList the category list + */ + public void setCategoryList(List<String> categoryList) { + if (categoryList != null && !categoryList.isEmpty()) { + List<String> lowerCaseCategoryList = new ArrayList<>(); + lowerCaseCategoryList + .addAll(categoryList.stream().map(String::toLowerCase).collect(Collectors.toList())); + this.categoryList = lowerCaseCategoryList; + } else { + this.categoryList = categoryList; + } + } + + public Date getTimestamp() { + return timestamp; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + public String getUser() { + return user; + } + + public void setUser(String user) { + this.user = user; + } + + public List<String> getSupportedModels() { + return supportedModels; + } + + public void setSupportedModels(List<String> supportedModels) { + this.supportedModels = supportedModels; + } + + public List<String> getSupportedComponents() { + return supportedComponents; + } + + public void setSupportedComponents(List<String> supportedComponents) { + this.supportedComponents = supportedComponents; + } + + public String getData() { + return data; + } + + public void setData(String data) { + this.data = data; + } + + /** + * To dto action. + * + * @return the action + */ + public Action toDto() { + //Action destination = new Action(); + + Action destination = JsonUtil.json2Object(this.getData(), Action.class); + destination.setData(this.getData()); + destination.setTimestamp(this.getTimestamp()); + destination.setUser(this.getUser()); + destination.setData(this.getData()); + return destination; + } + + /*private List<HashMap<String,String>> createMapFromList(List<String> list, String idName){ + List<HashMap<String,String>> keyValueList = new ArrayList<>(); + if(list != null && !list.isEmpty()){ + for(String attributeId : list){ + HashMap<String,String> attributeIdMap = new HashMap<>(); + attributeIdMap.put(idName,attributeId); + keyValueList.add(attributeIdMap); + } + return keyValueList; + } + return null; + }*/ +} diff --git a/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/dao/types/EcompComponentEntity.java b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/dao/types/EcompComponentEntity.java new file mode 100644 index 0000000000..9a71023629 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/dao/types/EcompComponentEntity.java @@ -0,0 +1,73 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.action.dao.types; + +import com.datastax.driver.mapping.annotations.Column; +import com.datastax.driver.mapping.annotations.PartitionKey; +import com.datastax.driver.mapping.annotations.Table; +import org.openecomp.sdc.action.types.EcompComponent; + +@Table(keyspace = "dox", name = "ECOMPComponent") +public class EcompComponentEntity { + + @PartitionKey + @Column(name = "id") + private String id; + + @Column(name = "name") + private String name; + + public EcompComponentEntity() { + } + + public EcompComponentEntity(String id, String name) { + this.id = id; + this.name = name; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + /** + * To dto ecomp component. + * + * @return the ecomp component + */ + public EcompComponent toDto() { + EcompComponent destination = new EcompComponent(); + destination.setId(this.getId()); + destination.setName(this.getName()); + return destination; + } +} diff --git a/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/errors/ActionErrorConstants.java b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/errors/ActionErrorConstants.java new file mode 100644 index 0000000000..092d9abee5 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/errors/ActionErrorConstants.java @@ -0,0 +1,136 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.action.errors; + +public class ActionErrorConstants { + + //Error Codes + public static final String ACTION_REQUEST_INVALID_GENERIC_CODE = "ACT0001"; + public static final String ACTION_AUTHENTICATION_ERR_CODE = "ACT1000"; + public static final String ACTION_AUTHORIZATION_ERR_CODE = "ACT1001"; + public static final String ACTION_INVALID_INSTANCE_ID_CODE = "ACT1002"; + public static final String ACTION_INVALID_REQUEST_ID_CODE = "ACT1003"; + public static final String ACTION_INVALID_PARAM_CODE = "ACT1004"; + //Operation <status> is not supported + public static final String ACTION_INVALID_REQUEST_BODY_CODE = "ACT1005"; + //ACTION_REQUEST_BODY_EMPTY + public static final String ACTION_UPDATE_NOT_ALLOWED_CODE_NAME = "ACT1007"; + public static final String ACTION_CHECKOUT_ON_LOCKED_ENTITY = "ACT1008"; + public static final String ACTION_ENTITY_UNIQUE_VALUE_ERROR = "ACT1009"; + + public static final String ACTION_INVALID_SEARCH_CRITERIA = "ACT1011"; + public static final String ACTION_MULT_SEARCH_CRITERIA = "ACT1012"; + public static final String ACTION_UPDATE_ON_UNLOCKED_ENTITY = "ACT1013"; + public static final String ACTION_UPDATE_INVALID_VERSION = "ACT1014"; + public static final String ACTION_UPDATE_NOT_ALLOWED_CODE = "ACT1015"; + + public static final String ACTION_CHECKIN_ON_UNLOCKED_ENTITY = "ACT1017"; + public static final String ACTION_SUBMIT_FINALIZED_ENTITY_NOT_ALLOWED = "ACT1018"; + public static final String ACTION_SUBMIT_LOCKED_ENTITY_NOT_ALLOWED = "ACT1019"; + public static final String ACTION_UNDO_CHECKOUT_ON_UNLOCKED_ENTITY = "ACT1020"; + public static final String ACTION_NOT_LOCKED_CODE = "ACT1021"; + public static final String ACTION_ARTIFACT_CHECKSUM_ERROR_CODE = "ACT1022"; + public static final String ACTION_ARTIFACT_TOO_BIG_ERROR_CODE = "ACT1023"; + public static final String ACTION_ARTIFACT_ALREADY_EXISTS_CODE = "ACT1025"; + public static final String ACTION_ARTIFACT_UPDATE_READ_ONLY = "ACT1026"; + public static final String ACTION_ARTIFACT_DELETE_READ_ONLY = "ACT1027"; + public static final String ACTION_ARTIFACT_INVALID_PROTECTION_CODE = "ACT1028"; + public static final String ACTION_ARTIFACT_INVALID_NAME_CODE = "ACT1029"; + + public static final String ACTION_EDIT_ON_ENTITY_LOCKED_BY_OTHER_USER = "ACT1041"; + public static final String ACTION_CHECKIN_ON_ENTITY_LOCKED_BY_OTHER_USER = "ACT1042"; + public static final String ACTION_CHECKOUT_ON_LOCKED_ENTITY_OTHER_USER = "ACT1043"; + public static final String ACTION_UNDO_CHECKOUT_ON_ENTITY_LOCKED_BY_OTHER_USER = "ACT1044"; + public static final String ACTION_ENTITY_NOT_EXIST_CODE = "ACT1045"; + public static final String ACTION_ARTIFACT_ENTITY_NOT_EXIST_CODE = "ACT1046"; + public static final String ACTION_ARTIFACT_DEL_LOCKED_OTHER_USER_CODE = "ACT1047"; + public static final String ACTION_DELETE_ON_LOCKED_ENTITY_CODE = "ACT1048"; + + public static final String ACTION_INTERNAL_SERVER_ERR_CODE = "ACT1060"; + public static final String ACTION_QUERY_FAILURE_CODE = "QUERY_FAILURE"; + public static final String ACTION_QUERY_FAILURE_MSG = "Query Failure"; + + + //Error Messages + public static final String ACTION_REQUEST_BODY_EMPTY = "Request Body is missing"; + //"The API failed due to missing body"; + public static final String ACTION_REQUEST_MISSING_MANDATORY_PARAM = + "Missing mandatory parameter(s) : "; + public static final String ACTION_REQUEST_ECOMP_INSTANCE_ID_INVALID = + "X-ECOMP-InstanceID HTTP header missing or empty"; + public static final String ACTION_REQUEST_ECOMP_REQUEST_ID_INVALID = + "X-ECOMP-RequestID HTTP header missing or empty"; + public static final String ACTION_REQUEST_CONTENT_TYPE_INVALID = + "Content-Type HTTP header missing or empty"; + public static final String ACTION_REQUEST_AUTHORIZATION_HEADER_INVALID = + "Authentication is required to use the API"; + public static final String ACTION_REQUEST_INVALID_NAME = + "Invalid syntax for action name. No whitespaces allowed."; + public static final String ACTION_REQUEST_FILTER_PARAM_INVALID = + "Invalid Search filter criteria provided"; + public static final String ACTION_FILTER_MULTIPLE_QUERY_PARAM_NOT_SUPPORTED = + "Multiple filter criteria are not supported"; + //"Operation supports filter by one property at a time"; + public static final String ACTION_ARTIFACT_ENTITY_NOT_EXIST = "Specified artifact is not found"; + public static final String ACTION_REQUEST_ARTIFACT_CHECKSUM_ERROR = "Checksum error"; + public static final String ACTION_REQUEST_ARTIFACT_INVALID_PROTECTION_VALUE = + "Invalid artifact protection value"; + + public static final String ACTION_ARTIFACT_INVALID_NAME = + "Artifact name cannot contain any of the following characters : #<>$+%!`&*'|{}?=/:@ " + + "including whitespaces, double quotes and back-slash"; + public static final String ACTION_ARTIFACT_READ_FILE_ERROR = "Error Occurred while reading file"; + public static final String ACTION_REQUEST_ARTIFACT_OPERATION_ALLOWED = + "Artifacts cannot be created/updated using this operation"; + public static final String ACTION_ARTIFACT_TOO_BIG_ERROR = + "Operation is not allowed. Artifact size exceeds the maximum file size limit (20MB)."; + + //Business Validation Error messages + public static final String ACTION_UPDATE_NOT_ALLOWED_FOR_NAME = + "Action Name update is not allowed"; + public static final String ACTION_UPDATE_PARAM_INVALID = + "Update not allowed for the parameter(s) : %s"; + public static final String ACTION_ENTITY_NOT_EXIST = "Specified Action is not found"; + public static final String ACTION_REQUESTED_VERSION_INVALID = "Invalid requested version : %s"; + public static final String ACTION_UNSUPPORTED_OPERATION = "Operation %s not supported"; + public static final String ACTION_ENTITY_UNIQUE_VALUE_MSG = + "%s with the value '%s' already exists."; + public static final String ACTION_ARTIFACT_ALREADY_EXISTS = + "Artifact name already exists for Action with id %s. Please use another name."; + public static final String ACTION_ENTITY_INTERNAL_SERVER_ERROR_MSG = + "The request failed due to an internal ASDC problem. ECOMP Component should continue the " + + "attempts, with corrected data if required, to create the resource."; + public static final String ACTION_ARTIFACT_DELETE_READ_ONLY_MSG = + "Cannot delete read only artifact."; + public static final String ACTION_ARTIFACT_UPDATE_READ_ONLY_MSG = + "Cannot update read only artifact."; + public static final String ACTION_NOT_LOCKED_MSG = + "Operation is not allowed. Action status should be Locked."; + public static final String ACTION_ARTIFACT_UPDATE_NAME_INVALID = + "Artifact name cannot be updated."; + public static final String ACTION_ARTIFACT_DEL_LOCKED_OTHER_USER = + "Cannot delete artifact since it is locked by other user %s."; + public static final String UNDO_CHECKOUT_ON_UNLOCKED_ENTITY_MSG = + "Can not undo checkout on versionable entity %s with id %s since it is not checked out."; + public static final String UNDO_CHECKOUT_ON_ENTITY_LOCKED_BY_OTHER_USER_MSG = + "Can not undo checkout on versionable entity %s with id" + + " %s since it is checked out by other user: %s."; +} diff --git a/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/errors/ActionException.java b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/errors/ActionException.java new file mode 100644 index 0000000000..fff88d6f84 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/errors/ActionException.java @@ -0,0 +1,52 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.action.errors; + +public class ActionException extends RuntimeException { + + private String errorCode; + private String description; + + public ActionException() { + + } + + public ActionException(String errorCode, String description) { + this.errorCode = errorCode; + this.description = description; + } + + public String getErrorCode() { + return errorCode; + } + + public void setErrorCode(String errorCode) { + this.errorCode = errorCode; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } +} diff --git a/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/errors/ActionExceptionMapper.java b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/errors/ActionExceptionMapper.java new file mode 100644 index 0000000000..23c14aaaa2 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/errors/ActionExceptionMapper.java @@ -0,0 +1,114 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.action.errors; + +import org.openecomp.sdc.action.ActionConstants; + +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import javax.ws.rs.ext.ExceptionMapper; + +public class ActionExceptionMapper implements ExceptionMapper<ActionException> { + + @Override + public Response toResponse(ActionException actionException) { + Response response; + String errorCode = actionException.getErrorCode(); + switch (errorCode) { + case ActionErrorConstants.ACTION_REQUEST_INVALID_GENERIC_CODE: + case ActionErrorConstants.ACTION_INVALID_INSTANCE_ID_CODE: + case ActionErrorConstants.ACTION_INVALID_REQUEST_ID_CODE: + case ActionErrorConstants.ACTION_INVALID_REQUEST_BODY_CODE: + case ActionErrorConstants.ACTION_INVALID_PARAM_CODE: + case ActionErrorConstants.ACTION_UPDATE_NOT_ALLOWED_FOR_NAME: + case ActionErrorConstants.ACTION_CHECKOUT_ON_LOCKED_ENTITY: + case ActionErrorConstants.ACTION_ENTITY_UNIQUE_VALUE_ERROR: + case ActionErrorConstants.ACTION_INVALID_SEARCH_CRITERIA: + case ActionErrorConstants.ACTION_MULT_SEARCH_CRITERIA: + case ActionErrorConstants.ACTION_UPDATE_ON_UNLOCKED_ENTITY: + case ActionErrorConstants.ACTION_UPDATE_INVALID_VERSION: + case ActionErrorConstants.ACTION_UPDATE_NOT_ALLOWED_CODE: + case ActionErrorConstants.ACTION_CHECKIN_ON_UNLOCKED_ENTITY: + case ActionErrorConstants.ACTION_SUBMIT_FINALIZED_ENTITY_NOT_ALLOWED: + case ActionErrorConstants.ACTION_SUBMIT_LOCKED_ENTITY_NOT_ALLOWED: + case ActionErrorConstants.ACTION_UNDO_CHECKOUT_ON_UNLOCKED_ENTITY: + case ActionErrorConstants.ACTION_UPDATE_NOT_ALLOWED_CODE_NAME: + case ActionErrorConstants.ACTION_ARTIFACT_CHECKSUM_ERROR_CODE: + case ActionErrorConstants.ACTION_ARTIFACT_ALREADY_EXISTS_CODE: + case ActionErrorConstants.ACTION_ARTIFACT_INVALID_NAME_CODE: + case ActionErrorConstants.ACTION_ARTIFACT_TOO_BIG_ERROR_CODE: + case ActionErrorConstants.ACTION_ARTIFACT_INVALID_PROTECTION_CODE: + case ActionErrorConstants.ACTION_ARTIFACT_DELETE_READ_ONLY: + case ActionErrorConstants.ACTION_NOT_LOCKED_CODE: + response = Response + .status(Response.Status.BAD_REQUEST) + .entity(new ActionExceptionResponse(errorCode, + Response.Status.BAD_REQUEST.getReasonPhrase(), actionException.getDescription())) + .type(MediaType.APPLICATION_JSON) + .build(); + break; + case ActionErrorConstants.ACTION_AUTHENTICATION_ERR_CODE: + response = Response + .status(Response.Status.UNAUTHORIZED) + .header(ActionConstants.WWW_AUTHENTICATE_HEADER_PARAM, + ActionErrorConstants.ACTION_REQUEST_AUTHORIZATION_HEADER_INVALID) + .entity(new ActionExceptionResponse(errorCode, + Response.Status.UNAUTHORIZED.getReasonPhrase(), actionException.getDescription())) + .type(MediaType.APPLICATION_JSON) + .build(); + break; + case ActionErrorConstants.ACTION_AUTHORIZATION_ERR_CODE: + case ActionErrorConstants.ACTION_EDIT_ON_ENTITY_LOCKED_BY_OTHER_USER: + case ActionErrorConstants.ACTION_CHECKIN_ON_ENTITY_LOCKED_BY_OTHER_USER: + case ActionErrorConstants.ACTION_CHECKOUT_ON_LOCKED_ENTITY_OTHER_USER: + case ActionErrorConstants.ACTION_UNDO_CHECKOUT_ON_ENTITY_LOCKED_BY_OTHER_USER: + case ActionErrorConstants.ACTION_DELETE_ON_LOCKED_ENTITY_CODE: + case ActionErrorConstants.ACTION_ARTIFACT_DEL_LOCKED_OTHER_USER_CODE: + case ActionErrorConstants.ACTION_ARTIFACT_UPDATE_READ_ONLY: + response = Response + .status(Response.Status.FORBIDDEN) + .entity( + new ActionExceptionResponse(errorCode, Response.Status.FORBIDDEN.getReasonPhrase(), + actionException.getDescription())).type(MediaType.APPLICATION_JSON) + .build(); + break; + case ActionErrorConstants.ACTION_ENTITY_NOT_EXIST_CODE: + case ActionErrorConstants.ACTION_ARTIFACT_ENTITY_NOT_EXIST_CODE: + response = Response + .status(Response.Status.NOT_FOUND) + .entity( + new ActionExceptionResponse(errorCode, Response.Status.NOT_FOUND.getReasonPhrase(), + actionException.getDescription())).type(MediaType.APPLICATION_JSON) + .build(); + break; + case ActionErrorConstants.ACTION_INTERNAL_SERVER_ERR_CODE: + default: + response = Response + .status(Response.Status.INTERNAL_SERVER_ERROR) + .entity(new ActionExceptionResponse(errorCode, + Response.Status.INTERNAL_SERVER_ERROR.getReasonPhrase(), + actionException.getDescription())) + .type(MediaType.APPLICATION_JSON) + .build(); + } + return response; + } +} diff --git a/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/errors/ActionExceptionResponse.java b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/errors/ActionExceptionResponse.java new file mode 100644 index 0000000000..51848464a7 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/errors/ActionExceptionResponse.java @@ -0,0 +1,66 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.action.errors; + +public class ActionExceptionResponse { + private String code; + private String description; + private String message; + + /** + * Instantiates a new Action exception response. + * + * @param code the code + * @param description the description + * @param message the message + */ + public ActionExceptionResponse(String code, String description, String message) { + this.code = code; + this.description = description; + this.message = message; + } + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + +} diff --git a/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/logging/CategoryLogLevel.java b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/logging/CategoryLogLevel.java new file mode 100644 index 0000000000..d87bed310f --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/logging/CategoryLogLevel.java @@ -0,0 +1,29 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.action.logging; + +public enum CategoryLogLevel { + INFO, + WARN, + DEBUG, + ERROR, + FATAL +} diff --git a/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/logging/StatusCode.java b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/logging/StatusCode.java new file mode 100644 index 0000000000..b0d5bab12b --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/logging/StatusCode.java @@ -0,0 +1,26 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.action.logging; + +public enum StatusCode { + COMPLETE, + ERROR +} diff --git a/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/types/Action.java b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/types/Action.java new file mode 100644 index 0000000000..176d443a81 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/types/Action.java @@ -0,0 +1,255 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.action.types; + +import org.openecomp.sdc.action.ActionConstants; +import org.openecomp.sdc.action.dao.types.ActionEntity; +import org.openecomp.sdc.versioning.dao.types.Version; + +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.List; + +public class Action implements Comparable { + private String actionUuId; + private String actionInvariantUuId; + private String version; + private ActionStatus status; + private String name; + private String displayName; + private String endpointUri; + private List<String> vendorList; + private List<String> categoryList; + private Date timestamp; + private String user; + private List<HashMap<String, String>> supportedModels; + private List<HashMap<String, String>> supportedComponents; + //private List<HashMap<String,String>> artifacts; + private List<ActionArtifact> artifacts; + private String data; + + public Action() { + } + + /** + * Instantiates a new Action. + * + * @param action the action + */ + public Action(Action action) { + this.actionUuId = action.getActionUuId(); + this.actionInvariantUuId = action.getActionInvariantUuId(); + this.name = action.getName(); + this.setDisplayName(action.getDisplayName()); + this.setVendorList(action.getVendorList()); + this.setCategoryList(action.getCategoryList()); + this.setTimestamp(action.getTimestamp()); + this.setUser(action.getUser()); + this.version = action.getVersion(); + this.status = action.getStatus(); + this.data = action.getData(); + this.supportedComponents = action.getSupportedComponents(); + this.supportedModels = action.getSupportedModels(); + this.artifacts = action.getArtifacts(); + } + + public String getActionUuId() { + return actionUuId; + } + + public void setActionUuId(String actionUuId) { + this.actionUuId = actionUuId; + } + + public String getActionInvariantUuId() { + return actionInvariantUuId; + } + + public void setActionInvariantUuId(String actionInvariantUuId) { + this.actionInvariantUuId = actionInvariantUuId; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public ActionStatus getStatus() { + return status; + } + + public void setStatus(ActionStatus status) { + this.status = status; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDisplayName() { + return displayName; + } + + public void setDisplayName(String displayName) { + this.displayName = displayName; + } + + public String getEndpointUri() { + return endpointUri; + } + + public void setEndpointUri(String endpointUri) { + this.endpointUri = endpointUri; + } + + public List<String> getVendorList() { + return vendorList; + } + + public void setVendorList(List<String> vendorList) { + this.vendorList = vendorList; + } + + public List<String> getCategoryList() { + return categoryList; + } + + public void setCategoryList(List<String> categoryList) { + this.categoryList = categoryList; + } + + public Date getTimestamp() { + return timestamp; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + public String getUser() { + return user; + } + + public void setUser(String user) { + this.user = user; + } + + public List<HashMap<String, String>> getSupportedModels() { + return supportedModels; + } + + public void setSupportedModels(List<HashMap<String, String>> supportedModels) { + this.supportedModels = supportedModels; + } + + public List<HashMap<String, String>> getSupportedComponents() { + return supportedComponents; + } + + public void setSupportedComponents(List<HashMap<String, String>> supportedComponents) { + this.supportedComponents = supportedComponents; + } + + public List<ActionArtifact> getArtifacts() { + return artifacts; + } + + public void setArtifacts(List<ActionArtifact> artifacts) { + this.artifacts = artifacts; + } + + public String getData() { + return data; + } + + public void setData(String data) { + this.data = data; + } + + /** + * To entity action entity. + * + * @return the action entity + */ + public ActionEntity toEntity() { + ActionEntity destination = new ActionEntity(); + + destination + .setActionUuId(this.getActionUuId() != null ? this.getActionUuId().toUpperCase() : null); + destination.setActionInvariantUuId( + this.getActionInvariantUuId() != null ? this.getActionInvariantUuId().toUpperCase() : null); + destination.setName(this.getName() != null ? this.getName().toLowerCase() : null); + destination.setVendorList(this.getVendorList()); + destination.setCategoryList(this.getCategoryList()); + destination.setTimestamp(this.getTimestamp()); + destination.setUser(this.getUser()); + destination.setVersion(Version.valueOf(this.getVersion())); + if (this.getStatus() != null) { + destination.setStatus(this.getStatus().name()); + } + destination.setSupportedComponents( + getIdFromMap(this.getSupportedComponents(), ActionConstants.SUPPORTED_COMPONENTS_ID)); + destination.setSupportedModels( + getIdFromMap(this.getSupportedModels(), ActionConstants.SUPPORTED_MODELS_VERSION_ID)); + destination.setData(this.getData()); + return destination; + } + + private List<String> getIdFromMap(List<HashMap<String, String>> map, String idName) { + List<String> list = new ArrayList<>(); + if (map != null && !map.isEmpty()) { + map.forEach(entry -> { + if (entry.containsKey(idName)) { + list.add(entry.get(idName) != null ? entry.get(idName).toLowerCase() : null); + } + }); + return list; + } + return null; + } + + @Override + public int compareTo(Object object) { + Action obj = (Action) object; + Version thisVersion = Version.valueOf(this.version); + Version objVersion = Version.valueOf(obj.getVersion()); + if (obj.getName().compareTo(this.getName()) == 0) { + return compareVersions(objVersion, thisVersion); + } + return obj.getName().compareTo(this.getName()); + } + + private int compareVersions(Version objVersion, Version thisVersion) { + if (objVersion.getMajor() == thisVersion.getMajor()) { + return Integer.compare(objVersion.getMinor(), thisVersion.getMinor()); + } + return Integer.compare(objVersion.getMajor(), thisVersion.getMajor()); + } + +} diff --git a/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/types/ActionArtifact.java b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/types/ActionArtifact.java new file mode 100644 index 0000000000..ef41673541 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/types/ActionArtifact.java @@ -0,0 +1,139 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.action.types; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import org.openecomp.sdc.action.dao.types.ActionArtifactEntity; + +import java.nio.ByteBuffer; +import java.util.Date; + +public class ActionArtifact { + private String artifactUuId; + + @JsonIgnore + private Integer effectiveVersion; + + private String artifactName; + private String artifactLabel; + private String artifactCategory; + private String artifactDescription; + private String artifactProtection; + private Date timestamp; + private byte[] artifact; + + public String getArtifactUuId() { + return artifactUuId; + } + + public void setArtifactUuId(String artifactUuId) { + this.artifactUuId = artifactUuId; + } + + public Integer getEffectiveVersion() { + return effectiveVersion; + } + + public void setEffectiveVersion(Integer effectiveVersion) { + this.effectiveVersion = effectiveVersion; + } + + public String getArtifactName() { + return artifactName; + } + + public void setArtifactName(String artifactName) { + this.artifactName = artifactName; + } + + public String getArtifactLabel() { + return artifactLabel; + } + + public void setArtifactLabel(String artifactLabel) { + this.artifactLabel = artifactLabel; + } + + public String getArtifactCategory() { + return artifactCategory; + } + + public void setArtifactCategory(String artifactCategory) { + this.artifactCategory = artifactCategory; + } + + public String getArtifactDescription() { + return artifactDescription; + } + + public void setArtifactDescription(String artifactDescription) { + this.artifactDescription = artifactDescription; + } + + public String getArtifactProtection() { + return artifactProtection; + } + + public void setArtifactProtection(String artifactProtection) { + this.artifactProtection = artifactProtection; + } + + public Date getTimestamp() { + return timestamp; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + public byte[] getArtifact() { + return artifact; + } + + public void setArtifact(byte[] artifact) { + this.artifact = artifact; + } + + /** + * To entity action artifact entity. + * + * @return the action artifact entity + */ + public ActionArtifactEntity toEntity() { + ActionArtifactEntity destination = new ActionArtifactEntity(); + destination.setArtifactUuId(this.getArtifactUuId()); + destination.setEffectiveVersion(this.getEffectiveVersion()); + destination.setArtifact(ByteBuffer.wrap(this.getArtifact())); + + return destination; + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof ActionArtifact) { + ActionArtifact temp = (ActionArtifact) obj; + if (artifactUuId.equals(temp.getArtifactUuId())) { + return true; + } + } + return false; + } +} diff --git a/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/types/ActionArtifactProtection.java b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/types/ActionArtifactProtection.java new file mode 100644 index 0000000000..636f24d781 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/types/ActionArtifactProtection.java @@ -0,0 +1,26 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.action.types; + +public enum ActionArtifactProtection { + readOnly, + readWrite +} diff --git a/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/types/ActionLogResponseCode.java b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/types/ActionLogResponseCode.java new file mode 100644 index 0000000000..c3de8aa4dc --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/types/ActionLogResponseCode.java @@ -0,0 +1,90 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.action.types; + +import java.util.HashMap; +import java.util.Map; + +public enum ActionLogResponseCode { + + MISSING_AUTHORIZATION(100), + FORBIDDEN(101), + UPDATE_ON_LOCKED_ENTITY(102), + CHECKIN_ON_LOCKED_ENTITY_OTHER_USER(103), + CHECKOUT_ON_LOCKED_ENTITY(104), + UNDO_CHECKOUT_ON_LOCKED_ENTITY(105), + DELETE_ARTIFACT_ON_LOCKED_ENTITY(106), + DELETE_ON_LOCKED_ENTITY_OTHER_USER(107), + INTERNAL_SERVER_ERROR(201), + MISSING_MANDATORY_PARAMS(300), + MISSING_INSTANCE_ID_HEADER(301), + MISSING_REQUEST_ID_HEADER(302), + MISSING_REQUEST_BODY(303), + INVALID_SEARCH_FILTER_CRITERIA(304), + INVALID_REQUESTED_VERSION(305), + CHECKSUM_ERROR(306), + ARTIFACT_TOO_BIG(307), + ACTION_NOT_FOUND(308), + ARTIFACT_NOT_FOUND(309), + METHOD_NOT_ALLOWED(310), + INVALID_REQUEST_PARAM(311), + ARTIFACT_PROTECTION_INVALID(312), + ACTION_NAME_UPDATE_NOT_ALLOWED(501), + //METHOD_NOT_ALLOWED(502), + ACTION_NAME_ALREADY_EXISTS(503), + MULTIPLE_FILTER_CRITERIA_NOT_SUPPORTED(504), + UPDATE_ON_UNLOCKED_ENTITY(505), + UPDATE_NOT_ALLOWED(506), + //METHOD_NOT_ALLOWED(507), + CHECKIN_ON_UNLOCKED_ENTITY(508), + SUBMIT_ON_FINAL_ENTITY(509), + SUBMIT_ON_LOCKED_ENTITY_OTHER_USER(510), + UNDO_CHECKOUT_ON_UNLOCKED_ENTITY(511), + ACTION_NOT_LOCKED(512), + ARTIFACT_ALREADY_EXISTS(513), + ARTIFACT_UPDATE_READ_ONLY(514), + ARTIFACT_DELETE_READ_ONLY(515), + ARTIFACT_NAME_INVALID(516), + ARTIFACT_CREATE_UPDATE_NOT_ALLOWED(518), + QUERY_FAILURE(519); + + private static Map<Integer, ActionLogResponseCode> mapValueToEnum = new HashMap<>(); + + static { + for (ActionLogResponseCode responseCode : ActionLogResponseCode.values()) { + mapValueToEnum.put(responseCode.value, responseCode); + } + } + + private int value; + + ActionLogResponseCode(int value) { + this.value = value; + } + + public static ActionLogResponseCode parseValue(int value) { + return mapValueToEnum.get(value); + } + + public int getValue() { + return value; + } +} diff --git a/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/types/ActionRequest.java b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/types/ActionRequest.java new file mode 100644 index 0000000000..1a20f9ecb7 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/types/ActionRequest.java @@ -0,0 +1,40 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.action.types; + +public enum ActionRequest { + CREATE_ACTION, + UPDATE_ACTION, + DELETE_ACTION, + GET_FILTERED_ACTIONS, + GET_ACTIONS_INVARIANT_ID, + GET_ECOMP_COMPONENTS, + ACTION_VERSIONING, + CHECKOUT_ACTION, + CHECKIN_ACTION, + SUBMIT_ACTION, + UNDO_CHECKOUT_ACTION, + UPLOAD_ARTIFACT, + DOWNLOAD_ARTIFACT, + UPDATE_ARTIFACT, + DELETE_ARTIFACT, + GET_ACTION_UUID +} diff --git a/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/types/ActionStatus.java b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/types/ActionStatus.java new file mode 100644 index 0000000000..af3516e1eb --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/types/ActionStatus.java @@ -0,0 +1,28 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.action.types; + +public enum ActionStatus { + Locked, + Available, + Final, + Deleted +} diff --git a/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/types/ActionSubOperation.java b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/types/ActionSubOperation.java new file mode 100644 index 0000000000..0dd97e6646 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/types/ActionSubOperation.java @@ -0,0 +1,59 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.action.types; + +public enum ActionSubOperation { + //Versioning operations + CREATE_ACTION_VERSION, + CREATE_ACTION_UNIQUE_VALUE, + GET_ACTION_VERSION, + //Action DAO operations + CREATE_ACTION_ENTITY, + GET_ACTIONENTITY_BY_ACTIONINVID, + GET_ACTIONENTITY_BY_ACTIONUUID, + GET_ACTIONENTITY_BY_VENDOR, + GET_ACTIONENTITY_BY_CATEGORY, + GET_ACTIONENTITY_BY_MODEL, + GET_ACTIONENTITY_BY_COMPONENT, + GET_ACTIONENTITY_BY_VERSION, + GET_ALL_ACTIONS, + GET_ACTIONINVID_BY_NAME, + GET_ECOMP_COMPONENTS_ENTITY, + GET_VERSIONINFO_FOR_ALL_ACTIONS, + GET_NAME_BY_ACTIONINVID, + CHECKOUT_ACTION, + UNDO_CHECKOUT_ACTION, + CHECKIN_ACTION, + SUBMIT_ACTION, + UPDATE_ACTION, + UPDATE_ACTION_STATUS, + DELETE_UNIQUEVALUE, + DELETE_ACTIONVERSION, + DELETE_ARTIFACT, + DELETE_ACTION, + //Validations + VALIDATE_ACTION_UNIQUE_NAME, + //Artifacts + GET_ARTIFACT_BY_ARTIFACTUUID, + CREATE_ACTION_ARTIFACT, + UPDATE_ACTION_ARTIFACT, + DELETE_ACTION_ARTIFACT, +} diff --git a/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/types/EcompComponent.java b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/types/EcompComponent.java new file mode 100644 index 0000000000..cbcebb13ef --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/types/EcompComponent.java @@ -0,0 +1,104 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.action.types; + +import org.openecomp.sdc.action.dao.types.EcompComponentEntity; + +public class EcompComponent { + + private String id; + private String name; + + public EcompComponent() { + //Default constructor + } + + public EcompComponent(String name, String id) { + this.name = name; + this.id = id; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + /** + * To entity ecomp component entity. + * + * @return the ecomp component entity + */ + public EcompComponentEntity toEntity() { + EcompComponentEntity destination = new EcompComponentEntity(); + destination.setId(this.getId()); + destination.setName(this.getName()); + return destination; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((id == null) ? 0 : id.hashCode()); + result = prime * result + ((name == null) ? 0 : name.hashCode()); + return result; + } + + @Override + public boolean equals(Object object) { + if (this == object) { + return true; + } + if (object == null) { + return false; + } + if (this.getClass() != object.getClass()) { + return false; + } + EcompComponent obj = (EcompComponent) object; + if (id == null) { + if (obj.id != null) { + return false; + } + } else if (!id.equals(obj.id)) { + return false; + } + if (name == null) { + if (obj.name != null) { + return false; + } + } else if (!name.equals(obj.name)) { + return false; + } + return true; + } +} diff --git a/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/util/ActionUtil.java b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/util/ActionUtil.java new file mode 100644 index 0000000000..787f6abc26 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/util/ActionUtil.java @@ -0,0 +1,372 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.action.util; + +import static org.openecomp.sdc.action.ActionConstants.BEGIN_TIMESTAMP; +import static org.openecomp.sdc.action.ActionConstants.ELAPSED_TIME; +import static org.openecomp.sdc.action.ActionConstants.END_TIMESTAMP; +import static org.openecomp.sdc.action.ActionConstants.ERROR_CATEGORY; +import static org.openecomp.sdc.action.ActionConstants.ERROR_CODE; +import static org.openecomp.sdc.action.ActionConstants.ERROR_DESCRIPTION; +import static org.openecomp.sdc.action.ActionConstants.RESPONSE_CODE; +import static org.openecomp.sdc.action.ActionConstants.RESPONSE_DESCRIPTION; +import static org.openecomp.sdc.action.ActionConstants.SERVICE_METRIC_BEGIN_TIMESTAMP; +import static org.openecomp.sdc.action.ActionConstants.STATUS_CODE; +import static org.openecomp.sdc.action.ActionConstants.TARGET_ENTITY; +import static org.openecomp.sdc.action.ActionConstants.TARGET_SERVICE_NAME; +import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_ARTIFACT_ALREADY_EXISTS_CODE; +import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_ARTIFACT_CHECKSUM_ERROR_CODE; +import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_ARTIFACT_DELETE_READ_ONLY; +import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_ARTIFACT_DEL_LOCKED_OTHER_USER_CODE; +import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_ARTIFACT_ENTITY_NOT_EXIST_CODE; +import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_ARTIFACT_INVALID_NAME_CODE; +import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_ARTIFACT_INVALID_PROTECTION_CODE; +import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_ARTIFACT_TOO_BIG_ERROR_CODE; +import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_ARTIFACT_UPDATE_READ_ONLY; +import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_AUTHENTICATION_ERR_CODE; +import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_AUTHORIZATION_ERR_CODE; +import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_CHECKIN_ON_ENTITY_LOCKED_BY_OTHER_USER; +import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_CHECKIN_ON_UNLOCKED_ENTITY; +import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_CHECKOUT_ON_LOCKED_ENTITY; +import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_CHECKOUT_ON_LOCKED_ENTITY_OTHER_USER; +import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_DELETE_ON_LOCKED_ENTITY_CODE; +import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_EDIT_ON_ENTITY_LOCKED_BY_OTHER_USER; +import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_ENTITY_NOT_EXIST_CODE; +import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_ENTITY_UNIQUE_VALUE_ERROR; +import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_INTERNAL_SERVER_ERR_CODE; +import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_INVALID_INSTANCE_ID_CODE; +import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_INVALID_PARAM_CODE; +import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_INVALID_REQUEST_BODY_CODE; +import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_INVALID_REQUEST_ID_CODE; +import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_INVALID_SEARCH_CRITERIA; +import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_MULT_SEARCH_CRITERIA; +import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_NOT_LOCKED_CODE; +import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_QUERY_FAILURE_CODE; +import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_REQUEST_INVALID_GENERIC_CODE; +import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_SUBMIT_FINALIZED_ENTITY_NOT_ALLOWED; +import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_SUBMIT_LOCKED_ENTITY_NOT_ALLOWED; +import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_UNDO_CHECKOUT_ON_ENTITY_LOCKED_BY_OTHER_USER; +import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_UNDO_CHECKOUT_ON_UNLOCKED_ENTITY; +import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_UPDATE_INVALID_VERSION; +import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_UPDATE_NOT_ALLOWED_CODE; +import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_UPDATE_NOT_ALLOWED_CODE_NAME; +import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_UPDATE_ON_UNLOCKED_ENTITY; +import static org.openecomp.sdc.action.types.ActionLogResponseCode.ACTION_NAME_ALREADY_EXISTS; +import static org.openecomp.sdc.action.types.ActionLogResponseCode.ACTION_NAME_UPDATE_NOT_ALLOWED; +import static org.openecomp.sdc.action.types.ActionLogResponseCode.ACTION_NOT_FOUND; +import static org.openecomp.sdc.action.types.ActionLogResponseCode.ACTION_NOT_LOCKED; +import static org.openecomp.sdc.action.types.ActionLogResponseCode.ARTIFACT_ALREADY_EXISTS; +import static org.openecomp.sdc.action.types.ActionLogResponseCode.ARTIFACT_DELETE_READ_ONLY; +import static org.openecomp.sdc.action.types.ActionLogResponseCode.ARTIFACT_NAME_INVALID; +import static org.openecomp.sdc.action.types.ActionLogResponseCode.ARTIFACT_NOT_FOUND; +import static org.openecomp.sdc.action.types.ActionLogResponseCode.ARTIFACT_PROTECTION_INVALID; +import static org.openecomp.sdc.action.types.ActionLogResponseCode.ARTIFACT_TOO_BIG; +import static org.openecomp.sdc.action.types.ActionLogResponseCode.ARTIFACT_UPDATE_READ_ONLY; +import static org.openecomp.sdc.action.types.ActionLogResponseCode.CHECKIN_ON_LOCKED_ENTITY_OTHER_USER; +import static org.openecomp.sdc.action.types.ActionLogResponseCode.CHECKIN_ON_UNLOCKED_ENTITY; +import static org.openecomp.sdc.action.types.ActionLogResponseCode.CHECKOUT_ON_LOCKED_ENTITY; +import static org.openecomp.sdc.action.types.ActionLogResponseCode.CHECKSUM_ERROR; +import static org.openecomp.sdc.action.types.ActionLogResponseCode.DELETE_ARTIFACT_ON_LOCKED_ENTITY; +import static org.openecomp.sdc.action.types.ActionLogResponseCode.DELETE_ON_LOCKED_ENTITY_OTHER_USER; +import static org.openecomp.sdc.action.types.ActionLogResponseCode.INTERNAL_SERVER_ERROR; +import static org.openecomp.sdc.action.types.ActionLogResponseCode.INVALID_REQUESTED_VERSION; +import static org.openecomp.sdc.action.types.ActionLogResponseCode.INVALID_REQUEST_PARAM; +import static org.openecomp.sdc.action.types.ActionLogResponseCode.INVALID_SEARCH_FILTER_CRITERIA; +import static org.openecomp.sdc.action.types.ActionLogResponseCode.MISSING_AUTHORIZATION; +import static org.openecomp.sdc.action.types.ActionLogResponseCode.MISSING_INSTANCE_ID_HEADER; +import static org.openecomp.sdc.action.types.ActionLogResponseCode.MISSING_REQUEST_BODY; +import static org.openecomp.sdc.action.types.ActionLogResponseCode.MISSING_REQUEST_ID_HEADER; +import static org.openecomp.sdc.action.types.ActionLogResponseCode.MULTIPLE_FILTER_CRITERIA_NOT_SUPPORTED; +import static org.openecomp.sdc.action.types.ActionLogResponseCode.QUERY_FAILURE; +import static org.openecomp.sdc.action.types.ActionLogResponseCode.SUBMIT_ON_FINAL_ENTITY; +import static org.openecomp.sdc.action.types.ActionLogResponseCode.SUBMIT_ON_LOCKED_ENTITY_OTHER_USER; +import static org.openecomp.sdc.action.types.ActionLogResponseCode.UNDO_CHECKOUT_ON_LOCKED_ENTITY; +import static org.openecomp.sdc.action.types.ActionLogResponseCode.UNDO_CHECKOUT_ON_UNLOCKED_ENTITY; +import static org.openecomp.sdc.action.types.ActionLogResponseCode.UPDATE_NOT_ALLOWED; +import static org.openecomp.sdc.action.types.ActionLogResponseCode.UPDATE_ON_LOCKED_ENTITY; +import static org.openecomp.sdc.action.types.ActionLogResponseCode.UPDATE_ON_UNLOCKED_ENTITY; + +import org.openecomp.sdc.action.logging.CategoryLogLevel; +import org.openecomp.sdc.action.logging.StatusCode; +import org.openecomp.sdc.action.types.ActionLogResponseCode; +import org.openecomp.sdc.action.types.ActionSubOperation; +import org.slf4j.MDC; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.time.ZoneOffset; +import java.util.Date; +import java.util.TimeZone; + + +public class ActionUtil { + + private static final String UTC_DATE_FORMAT = "dd MMM yyyy kk:mm:ss z"; + private static final String LOG_UTC_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSS"; + + /** + * Get Current Timestamp in UTC format. + * + * @return Current Timestamp in UTC format. + */ + public static Date getCurrentTimeStampUtc() { + return Date.from(java.time.ZonedDateTime.now(ZoneOffset.UTC).toInstant()); + } + + /** + * Convert timestamp to UTC format date string. + * + * @param timeStamp UTC timestamp to be converted to the UTC Date format. + * @return UTC formatted Date string from timestamp. + */ + public static String getUtcDateStringFromTimestamp(Date timeStamp) { + DateFormat df = new SimpleDateFormat(UTC_DATE_FORMAT); + df.setTimeZone(TimeZone.getTimeZone("GMT")); + return df.format(timeStamp); + } + + /** + * Convert timestamp to UTC format date string. + * + * @param timeStamp UTC timestamp to be converted to the UTC Date format. + * @return UTC formatted Date string from timestamp. + */ + public static String getLogUtcDateStringFromTimestamp(Date timeStamp) { + DateFormat df = new SimpleDateFormat(LOG_UTC_DATE_FORMAT); + df.setTimeZone(TimeZone.getTimeZone("GMT")); + return df.format(timeStamp); + } + + /** + * Method to set up specific attributes MDC for the current logging operation. + * + * @param subOperation Request Name. + */ + public static void actionLogPreProcessor(ActionSubOperation subOperation, String targetEntity) { + MDC.put(BEGIN_TIMESTAMP, String.valueOf(System.currentTimeMillis())); + if (subOperation != null) { + MDC.put(TARGET_SERVICE_NAME, subOperation.name()); + } + + MDC.put(TARGET_ENTITY, targetEntity); + } + + /** + * Method to enhance the MDC after the logging operation for Metrics and Audit logs. + * + * @param statusCode Response code for the current operation. + */ + public static void actionLogPostProcessor(StatusCode statusCode) { + actionLogPostProcessor(statusCode, false); + } + + public static void actionLogPostProcessor(StatusCode statusCode, boolean isServiceMetricLog) { + actionLogPostProcessor(statusCode, null, isServiceMetricLog); + } + + public static void actionLogPostProcessor(StatusCode statusCode, String responseCode, + boolean isServiceMetricLog) { + actionLogPostProcessor(statusCode, responseCode, null, isServiceMetricLog); + } + + /** + * Method to enhance the MDC after the logging operation for Metrics and Audit logs. + * + * @param statusCode Response code for the current operation. + */ + + public static void actionLogPostProcessor(StatusCode statusCode, String responseCode, + String responseDescription, + boolean isServiceMetricLog) { + MDC.put(STATUS_CODE, statusCode.name()); + if (responseCode != null) { + int logResponseCode = getLogResponseCode(responseCode); + MDC.put(RESPONSE_CODE, Integer.toString(logResponseCode)); + } + MDC.put(RESPONSE_DESCRIPTION, responseDescription); + long beginTimestamp; + if (isServiceMetricLog) { + beginTimestamp = Long.valueOf(MDC.get(SERVICE_METRIC_BEGIN_TIMESTAMP)); + } else { + beginTimestamp = Long.valueOf(MDC.get(BEGIN_TIMESTAMP)); + } + long endTimestamp = System.currentTimeMillis(); + MDC.put(BEGIN_TIMESTAMP, getLogUtcDateStringFromTimestamp(new Date(beginTimestamp))); + MDC.put(END_TIMESTAMP, getLogUtcDateStringFromTimestamp(new Date(endTimestamp))); + MDC.put(ELAPSED_TIME, String.valueOf(endTimestamp - beginTimestamp)); + } + + /** + * Action Library Error logging Helper. + * + * @param errorCategory WARN or ERROR. + * @param errorCode Action Library exception code. + * @param errorDescription Description of the error. + */ + public static void actionErrorLogProcessor(CategoryLogLevel errorCategory, String errorCode, + String errorDescription) { + MDC.put(ERROR_CATEGORY, errorCategory.name()); + if (errorCode != null) { + String errorType = ""; + switch (errorCategory) { + case WARN: + errorType = "W"; + break; + case ERROR: + errorType = "E"; + break; + case FATAL: + errorType = "F"; + break; + default: + break; + } + MDC.put(ERROR_CODE, getLogResponseCode(errorCode) + errorType); + } + MDC.put(ERROR_DESCRIPTION, errorDescription); + } + + /** + * Method to convert Action Library exception codes to OPENECOMP Audit codes in {@link. + * ActionLogResponseCode} e.g: ACT1060 --> 201. + * + * @param errorCode Action library exception code. + * @return Audit log code corresponding to the Action Library exception. + */ + public static int getLogResponseCode(String errorCode) { + ActionLogResponseCode responseCode = INTERNAL_SERVER_ERROR; + switch (errorCode) { + case ACTION_REQUEST_INVALID_GENERIC_CODE: + responseCode = INVALID_REQUEST_PARAM; + break; + case ACTION_AUTHENTICATION_ERR_CODE: + break; + case ACTION_AUTHORIZATION_ERR_CODE: + responseCode = MISSING_AUTHORIZATION; + break; + case ACTION_INVALID_INSTANCE_ID_CODE: + responseCode = MISSING_INSTANCE_ID_HEADER; + break; + case ACTION_INVALID_REQUEST_ID_CODE: + responseCode = MISSING_REQUEST_ID_HEADER; + break; + case ACTION_INVALID_PARAM_CODE: + responseCode = INVALID_REQUEST_PARAM; + break; + case ACTION_INVALID_REQUEST_BODY_CODE: + responseCode = MISSING_REQUEST_BODY; + break; + case ACTION_UPDATE_NOT_ALLOWED_CODE_NAME: + responseCode = ACTION_NAME_UPDATE_NOT_ALLOWED; + break; + case ACTION_CHECKOUT_ON_LOCKED_ENTITY: + responseCode = CHECKOUT_ON_LOCKED_ENTITY; + break; + case ACTION_ENTITY_UNIQUE_VALUE_ERROR: + responseCode = ACTION_NAME_ALREADY_EXISTS; + break; + case ACTION_INVALID_SEARCH_CRITERIA: + responseCode = INVALID_SEARCH_FILTER_CRITERIA; + break; + case ACTION_MULT_SEARCH_CRITERIA: + responseCode = MULTIPLE_FILTER_CRITERIA_NOT_SUPPORTED; + break; + case ACTION_UPDATE_ON_UNLOCKED_ENTITY: + responseCode = UPDATE_ON_UNLOCKED_ENTITY; + break; + case ACTION_UPDATE_INVALID_VERSION: + responseCode = INVALID_REQUESTED_VERSION; + break; + case ACTION_UPDATE_NOT_ALLOWED_CODE: + responseCode = UPDATE_NOT_ALLOWED; + break; + case ACTION_CHECKIN_ON_UNLOCKED_ENTITY: + responseCode = CHECKIN_ON_UNLOCKED_ENTITY; + break; + case ACTION_SUBMIT_FINALIZED_ENTITY_NOT_ALLOWED: + responseCode = SUBMIT_ON_FINAL_ENTITY; + break; + case ACTION_SUBMIT_LOCKED_ENTITY_NOT_ALLOWED: + responseCode = SUBMIT_ON_LOCKED_ENTITY_OTHER_USER; + break; + case ACTION_UNDO_CHECKOUT_ON_UNLOCKED_ENTITY: + responseCode = UNDO_CHECKOUT_ON_UNLOCKED_ENTITY; + break; + case ACTION_NOT_LOCKED_CODE: + responseCode = ACTION_NOT_LOCKED; + break; + case ACTION_ARTIFACT_CHECKSUM_ERROR_CODE: + responseCode = CHECKSUM_ERROR; + break; + case ACTION_ARTIFACT_TOO_BIG_ERROR_CODE: + responseCode = ARTIFACT_TOO_BIG; + break; + case ACTION_ARTIFACT_ALREADY_EXISTS_CODE: + responseCode = ARTIFACT_ALREADY_EXISTS; + break; + case ACTION_ARTIFACT_UPDATE_READ_ONLY: + responseCode = ARTIFACT_UPDATE_READ_ONLY; + break; + case ACTION_ARTIFACT_DELETE_READ_ONLY: + responseCode = ARTIFACT_DELETE_READ_ONLY; + break; + case ACTION_ARTIFACT_INVALID_PROTECTION_CODE: + responseCode = ARTIFACT_PROTECTION_INVALID; + break; + case ACTION_ARTIFACT_INVALID_NAME_CODE: + responseCode = ARTIFACT_NAME_INVALID; + break; + case ACTION_EDIT_ON_ENTITY_LOCKED_BY_OTHER_USER: + responseCode = UPDATE_ON_LOCKED_ENTITY; + break; + case ACTION_CHECKIN_ON_ENTITY_LOCKED_BY_OTHER_USER: + responseCode = CHECKIN_ON_LOCKED_ENTITY_OTHER_USER; + break; + case ACTION_CHECKOUT_ON_LOCKED_ENTITY_OTHER_USER: + responseCode = CHECKOUT_ON_LOCKED_ENTITY; + break; + case ACTION_UNDO_CHECKOUT_ON_ENTITY_LOCKED_BY_OTHER_USER: + responseCode = UNDO_CHECKOUT_ON_LOCKED_ENTITY; + break; + case ACTION_ENTITY_NOT_EXIST_CODE: + responseCode = ACTION_NOT_FOUND; + break; + case ACTION_ARTIFACT_ENTITY_NOT_EXIST_CODE: + responseCode = ARTIFACT_NOT_FOUND; + break; + case ACTION_ARTIFACT_DEL_LOCKED_OTHER_USER_CODE: + responseCode = DELETE_ARTIFACT_ON_LOCKED_ENTITY; + break; + case ACTION_DELETE_ON_LOCKED_ENTITY_CODE: + responseCode = DELETE_ON_LOCKED_ENTITY_OTHER_USER; + break; + case ACTION_INTERNAL_SERVER_ERR_CODE: + responseCode = INTERNAL_SERVER_ERROR; + break; + case ACTION_QUERY_FAILURE_CODE: + responseCode = QUERY_FAILURE; + break; + default: + break; + } + return responseCode.getValue(); + } +} diff --git a/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/resources/factoryConfiguration.json b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/resources/factoryConfiguration.json new file mode 100644 index 0000000000..44da8f085e --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/resources/factoryConfiguration.json @@ -0,0 +1,4 @@ +{ + "org.openecomp.sdc.action.dao.ActionDaoFactory":"org.openecomp.sdc.action.dao.impl.ActionDaoFactoryImpl", + "org.openecomp.sdc.action.dao.ActionArtifactDaoFactory":"org.openecomp.sdc.action.dao.impl.ActionArtifactDaoFactoryImpl" +}
\ No newline at end of file diff --git a/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-core/pom.xml b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-core/pom.xml new file mode 100644 index 0000000000..3abcbb55e7 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-core/pom.xml @@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns="http://maven.apache.org/POM/4.0.0" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + + <parent> + <groupId>org.openecomp.sdc</groupId> + <artifactId>openecomp-sdc-action-lib</artifactId> + <version>1.0.0-SNAPSHOT</version> + </parent> + + + <artifactId>openecomp-sdc-action-core</artifactId> + + + + <dependencies> + <dependency> + <groupId>org.openecomp.sdc</groupId> + <artifactId>openecomp-sdc-action-api</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.openecomp.sdc</groupId> + <artifactId>openecomp-sdc-versioning-api</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.openecomp.sdc.sdc_common</groupId> + <artifactId>openecomp-logging-api</artifactId> + <version>${project.version}</version> + </dependency> + </dependencies> + +</project>
\ No newline at end of file diff --git a/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-core/src/main/java/org/openecomp/sdc/action/dao/impl/ActionArtifactDaoFactoryImpl.java b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-core/src/main/java/org/openecomp/sdc/action/dao/impl/ActionArtifactDaoFactoryImpl.java new file mode 100644 index 0000000000..2767c9eeca --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-core/src/main/java/org/openecomp/sdc/action/dao/impl/ActionArtifactDaoFactoryImpl.java @@ -0,0 +1,33 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.action.dao.impl; + +import org.openecomp.sdc.action.dao.ActionArtifactDao; +import org.openecomp.sdc.action.dao.ActionArtifactDaoFactory; + +public class ActionArtifactDaoFactoryImpl extends ActionArtifactDaoFactory { + private static final ActionArtifactDao INSTANCE = new ActionArtifactDaoImpl(); + + @Override + public ActionArtifactDao createInterface() { + return INSTANCE; + } +} diff --git a/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-core/src/main/java/org/openecomp/sdc/action/dao/impl/ActionArtifactDaoImpl.java b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-core/src/main/java/org/openecomp/sdc/action/dao/impl/ActionArtifactDaoImpl.java new file mode 100644 index 0000000000..3e884c24e3 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-core/src/main/java/org/openecomp/sdc/action/dao/impl/ActionArtifactDaoImpl.java @@ -0,0 +1,150 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.action.dao.impl; + +import static org.openecomp.sdc.action.ActionConstants.TARGET_ENTITY_DB; +import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_ENTITY_INTERNAL_SERVER_ERROR_MSG; +import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_INTERNAL_SERVER_ERR_CODE; +import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_QUERY_FAILURE_CODE; +import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_QUERY_FAILURE_MSG; +import static org.openecomp.sdc.action.util.ActionUtil.actionLogPostProcessor; + +import com.datastax.driver.core.exceptions.NoHostAvailableException; +import com.datastax.driver.mapping.Mapper; +import com.datastax.driver.mapping.Result; +import com.datastax.driver.mapping.annotations.Accessor; +import com.datastax.driver.mapping.annotations.Query; +import org.openecomp.core.dao.impl.CassandraBaseDao; +import org.openecomp.core.logging.api.Logger; +import org.openecomp.core.logging.api.LoggerFactory; +import org.openecomp.core.nosqldb.api.NoSqlDb; +import org.openecomp.core.nosqldb.factory.NoSqlDbFactory; +import org.openecomp.sdc.action.dao.ActionArtifactDao; +import org.openecomp.sdc.action.dao.types.ActionArtifactEntity; +import org.openecomp.sdc.action.errors.ActionException; +import org.openecomp.sdc.action.logging.CategoryLogLevel; +import org.openecomp.sdc.action.logging.StatusCode; +import org.openecomp.sdc.action.types.ActionArtifact; +import org.openecomp.sdc.action.types.ActionSubOperation; +import org.openecomp.sdc.action.util.ActionUtil; + +import java.util.Collection; +import java.util.List; + +public class ActionArtifactDaoImpl extends CassandraBaseDao<ActionArtifactEntity> + implements ActionArtifactDao { + private static final NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface(); + private static final Mapper<ActionArtifactEntity> mapper = + noSqlDb.getMappingManager().mapper(ActionArtifactEntity.class); + private static final ActionArtifactAccessor accessor = + noSqlDb.getMappingManager().createAccessor(ActionArtifactAccessor.class); + private final Logger log = (Logger) LoggerFactory.getLogger(this.getClass().getName()); + + @Override + protected Mapper<ActionArtifactEntity> getMapper() { + return mapper; + } + + @Override + protected Object[] getKeys(ActionArtifactEntity entity) { + return new Object[]{entity.getArtifactUuId(), entity.getEffectiveVersion()}; + } + + @Override + public Collection<ActionArtifactEntity> list(ActionArtifactEntity entity) { + return null; + } + + + @Override + public void uploadArtifact(ActionArtifact data) { + log.debug(" entering uploadArtifact with artifactName= " + data.getArtifactName()); + try { + ActionUtil.actionLogPreProcessor(ActionSubOperation.CREATE_ACTION_ARTIFACT, TARGET_ENTITY_DB); + this.create(data.toEntity()); + ActionUtil.actionLogPostProcessor(StatusCode.COMPLETE, null, "", false); + log.metrics(""); + } catch (NoHostAvailableException noHostAvailableException) { + logGenericException(noHostAvailableException); + throw new ActionException(ACTION_INTERNAL_SERVER_ERR_CODE, + ACTION_ENTITY_INTERNAL_SERVER_ERROR_MSG); + } + log.debug(" exit uploadArtifact with artifactName= " + data.getArtifactName()); + } + + @Override + public ActionArtifact downloadArtifact(int effectiveVersion, String artifactUuId) { + log.debug(" entering downloadArtifact with artifactUUID= " + artifactUuId); + ActionArtifact actionArtifact = null; + try { + ActionUtil + .actionLogPreProcessor(ActionSubOperation.GET_ARTIFACT_BY_ARTIFACTUUID, TARGET_ENTITY_DB); + Result<ActionArtifactEntity> result; + result = accessor.getArtifactByUuId(effectiveVersion, artifactUuId); + ActionUtil.actionLogPostProcessor(StatusCode.COMPLETE, null, "", false); + log.metrics(""); + List<ActionArtifactEntity> artifactEntities = result.all(); + if (artifactEntities != null && !artifactEntities.isEmpty()) { + ActionArtifactEntity artifactEntity = artifactEntities.get(0); + actionArtifact = artifactEntity.toDto(); + } + } catch (NoHostAvailableException noHostAvailableException) { + logGenericException(noHostAvailableException); + throw new ActionException(ACTION_INTERNAL_SERVER_ERR_CODE, + ACTION_ENTITY_INTERNAL_SERVER_ERROR_MSG); + } + log.debug(" exit downloadArtifact with artifactUUID= " + artifactUuId); + return actionArtifact; + } + + @Override + public void updateArtifact(ActionArtifact data) { + log.debug(" entering updateArtifact with artifactName= " + data.getArtifactName()); + try { + ActionUtil.actionLogPreProcessor(ActionSubOperation.UPDATE_ACTION_ARTIFACT, TARGET_ENTITY_DB); + this.update(data.toEntity()); + ActionUtil.actionLogPostProcessor(StatusCode.COMPLETE, null, "", false); + log.metrics(""); + } catch (NoHostAvailableException noHostAvailableException) { + logGenericException(noHostAvailableException); + throw new ActionException(ACTION_INTERNAL_SERVER_ERR_CODE, + ACTION_ENTITY_INTERNAL_SERVER_ERROR_MSG); + } + log.debug(" exit updateArtifact with artifactName= " + data.getArtifactName()); + } + + private void logGenericException(Exception exception) { + ActionUtil.actionLogPostProcessor(StatusCode.ERROR, ACTION_QUERY_FAILURE_CODE, + ACTION_ENTITY_INTERNAL_SERVER_ERROR_MSG, false); + log.metrics(""); + ActionUtil.actionErrorLogProcessor(CategoryLogLevel.FATAL, ACTION_QUERY_FAILURE_CODE, + ACTION_QUERY_FAILURE_MSG); + log.error(exception.getMessage()); + } + + @Accessor + interface ActionArtifactAccessor { + + @Query( + "SELECT * FROM action_artifact WHERE effective_version <= ? and artifactuuid = ? limit 1") + Result<ActionArtifactEntity> getArtifactByUuId(int effectiveVersion, String artifactUuId); + } +} diff --git a/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-core/src/main/java/org/openecomp/sdc/action/dao/impl/ActionDaoFactoryImpl.java b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-core/src/main/java/org/openecomp/sdc/action/dao/impl/ActionDaoFactoryImpl.java new file mode 100644 index 0000000000..66bd20687d --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-core/src/main/java/org/openecomp/sdc/action/dao/impl/ActionDaoFactoryImpl.java @@ -0,0 +1,33 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.action.dao.impl; + +import org.openecomp.sdc.action.dao.ActionDao; +import org.openecomp.sdc.action.dao.ActionDaoFactory; + +public class ActionDaoFactoryImpl extends ActionDaoFactory { + private static final ActionDao INSTANCE = new ActionDaoImpl(); + + @Override + public ActionDao createInterface() { + return INSTANCE; + } +} diff --git a/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-core/src/main/java/org/openecomp/sdc/action/dao/impl/ActionDaoImpl.java b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-core/src/main/java/org/openecomp/sdc/action/dao/impl/ActionDaoImpl.java new file mode 100644 index 0000000000..29b5171470 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-core/src/main/java/org/openecomp/sdc/action/dao/impl/ActionDaoImpl.java @@ -0,0 +1,583 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.action.dao.impl; + +import static com.datastax.driver.core.querybuilder.QueryBuilder.eq; +import static com.datastax.driver.core.querybuilder.QueryBuilder.in; +import static com.datastax.driver.core.querybuilder.QueryBuilder.set; +import static org.openecomp.core.nosqldb.impl.cassandra.CassandraSessionFactory.getSession; +import static org.openecomp.sdc.action.util.ActionUtil.actionLogPostProcessor; + +import com.datastax.driver.core.ResultSet; +import com.datastax.driver.core.Row; +import com.datastax.driver.core.Statement; +import com.datastax.driver.core.UDTValue; +import com.datastax.driver.core.exceptions.NoHostAvailableException; +import com.datastax.driver.core.querybuilder.QueryBuilder; +import com.datastax.driver.mapping.Mapper; +import com.datastax.driver.mapping.Result; +import com.datastax.driver.mapping.UDTMapper; +import com.datastax.driver.mapping.annotations.Accessor; +import com.datastax.driver.mapping.annotations.Query; +import org.openecomp.core.dao.impl.CassandraBaseDao; +import org.openecomp.core.logging.api.Logger; +import org.openecomp.core.logging.api.LoggerFactory; +import org.openecomp.core.nosqldb.api.NoSqlDb; +import org.openecomp.core.nosqldb.factory.NoSqlDbFactory; +import org.openecomp.core.utilities.json.JsonUtil; +import org.openecomp.sdc.action.ActionConstants; +import org.openecomp.sdc.action.dao.ActionDao; +import org.openecomp.sdc.action.dao.types.ActionEntity; +import org.openecomp.sdc.action.dao.types.EcompComponentEntity; +import org.openecomp.sdc.action.errors.ActionErrorConstants; +import org.openecomp.sdc.action.errors.ActionException; +import org.openecomp.sdc.action.logging.CategoryLogLevel; +import org.openecomp.sdc.action.logging.StatusCode; +import org.openecomp.sdc.action.types.Action; +import org.openecomp.sdc.action.types.ActionStatus; +import org.openecomp.sdc.action.types.ActionSubOperation; +import org.openecomp.sdc.action.types.EcompComponent; +import org.openecomp.sdc.action.util.ActionUtil; +import org.openecomp.sdc.versioning.VersioningManagerFactory; +import org.openecomp.sdc.versioning.dao.VersionInfoDao; +import org.openecomp.sdc.versioning.dao.VersionInfoDaoFactory; +import org.openecomp.sdc.versioning.dao.VersionInfoDeletedDao; +import org.openecomp.sdc.versioning.dao.VersionInfoDeletedDaoFactory; +import org.openecomp.sdc.versioning.dao.types.Version; +import org.openecomp.sdc.versioning.dao.types.VersionInfoDeletedEntity; +import org.openecomp.sdc.versioning.dao.types.VersionInfoEntity; +import org.openecomp.sdc.versioning.types.VersionableEntityMetadata; +import org.slf4j.MDC; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; + +public class ActionDaoImpl extends CassandraBaseDao<ActionEntity> implements ActionDao { + private static final NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface(); + private static final Mapper<ActionEntity> mapper = + noSqlDb.getMappingManager().mapper(ActionEntity.class); + private static final ActionAccessor accessor = + noSqlDb.getMappingManager().createAccessor(ActionAccessor.class); + private static final UDTMapper<Version> versionMapper = + noSqlDb.getMappingManager().udtMapper(Version.class); + private static final VersionInfoDao versionInfoDao = + VersionInfoDaoFactory.getInstance().createInterface(); + private static final VersionInfoDeletedDao versionInfoDeletedDao = + VersionInfoDeletedDaoFactory.getInstance().createInterface(); + + private final Logger log = (Logger) LoggerFactory.getLogger(this.getClass().getName()); + + + @Override + public void registerVersioning(String versionableEntityType) { + VersioningManagerFactory.getInstance().createInterface() + .register(versionableEntityType, new VersionableEntityMetadata( + mapper.getTableMetadata().getName(), + mapper.getTableMetadata().getPartitionKey().get(0).getName(), + mapper.getTableMetadata().getPartitionKey().get(1).getName())); + } + + @Override + public Action createAction(Action actionDto) { + try { + ActionUtil.actionLogPreProcessor( + ActionSubOperation.CREATE_ACTION_ENTITY, ActionConstants.TARGET_ENTITY_DB); + this.create(actionDto.toEntity()); + ActionUtil.actionLogPostProcessor(StatusCode.COMPLETE, null, "", false); + log.metrics(""); + return actionDto; + } catch (NoHostAvailableException noHostAvailableException) { + logGenericException(noHostAvailableException); + throw new ActionException(ActionErrorConstants.ACTION_INTERNAL_SERVER_ERR_CODE, + ActionErrorConstants.ACTION_ENTITY_INTERNAL_SERVER_ERROR_MSG); + } + } + + @Override + public Action updateAction(Action actionDto) { + try { + log.debug(" entering updateAction with actionUUID= " + actionDto.getActionUuId()); + ActionUtil + .actionLogPreProcessor(ActionSubOperation.UPDATE_ACTION, + ActionConstants.TARGET_ENTITY_DB); + this.update(actionDto.toEntity()); + ActionUtil.actionLogPostProcessor(StatusCode.COMPLETE, null, "", false); + log.metrics(""); + log.debug(" exit updateAction with actionUUID= " + actionDto.getActionUuId()); + return actionDto; + } catch (NoHostAvailableException noHostAvailableException) { + logGenericException(noHostAvailableException); + throw new ActionException(ActionErrorConstants.ACTION_INTERNAL_SERVER_ERR_CODE, + ActionErrorConstants.ACTION_ENTITY_INTERNAL_SERVER_ERROR_MSG); + } + } + + @Override + public void deleteAction(String actionInvariantUuId) { + try { + log.debug("entering deleteAction with actionInvariantUUID = " + actionInvariantUuId); + ActionUtil + .actionLogPreProcessor(ActionSubOperation.GET_ACTION_VERSION, + ActionConstants.TARGET_ENTITY_DB); + VersionInfoDeletedEntity activeVersionEntity = versionInfoDeletedDao.get( + new VersionInfoDeletedEntity(ActionConstants.ACTION_VERSIONABLE_TYPE, + actionInvariantUuId)); + ActionUtil.actionLogPostProcessor(StatusCode.COMPLETE, null, "", false); + log.metrics(""); + Version activeVersion = activeVersionEntity.getActiveVersion(); + Statement getNameFromInvUuId = QueryBuilder.select().column("name").from("dox", "Action") + .where(eq("actioninvariantuuid", actionInvariantUuId)) + .and(in("version", versionMapper.toUDT(activeVersion))); + ActionUtil + .actionLogPreProcessor(ActionSubOperation.GET_NAME_BY_ACTIONINVID, + ActionConstants.TARGET_ENTITY_DB); + ResultSet results = getSession().execute(getNameFromInvUuId); + ActionUtil.actionLogPostProcessor(StatusCode.COMPLETE, null, "", false); + log.metrics(""); + if (!results.isExhausted()) { + String name = results.one().getString("name"); + List<Version> versions = getVersionsByName(name); + updateActionStatusForDelete(actionInvariantUuId, versions); + } + } catch (NoHostAvailableException noHostAvailableException) { + logGenericException(noHostAvailableException); + throw new ActionException(ActionErrorConstants.ACTION_INTERNAL_SERVER_ERR_CODE, + ActionErrorConstants.ACTION_ENTITY_INTERNAL_SERVER_ERROR_MSG); + } + log.debug("exit deleteAction"); + } + + + @Override + public List<Action> getActionsByActionInvariantUuId(String actionInvariantUuId) { + List<Action> actions = new ArrayList<>(); + try { + log.debug(" entering getActionsByActionInvariantUUID with actionInvariantUUID= " + + actionInvariantUuId); + Set<Version> viewableVersions = new HashSet<>(); + VersionPredicate filter = new VersionPredicate(); + ActionUtil + .actionLogPreProcessor(ActionSubOperation.GET_ACTION_VERSION, + ActionConstants.TARGET_ENTITY_DB); + VersionInfoEntity versionInfoEntity = versionInfoDao + .get(new VersionInfoEntity(ActionConstants.ACTION_VERSIONABLE_TYPE, actionInvariantUuId)); + if (versionInfoEntity == null) { + //Check for action in the Delete version info table + VersionInfoDeletedEntity versionInfoDeletedEntity = versionInfoDeletedDao.get( + new VersionInfoDeletedEntity(ActionConstants.ACTION_VERSIONABLE_TYPE, + actionInvariantUuId)); + if (versionInfoDeletedEntity != null) { + viewableVersions = versionInfoDeletedEntity.getViewableVersions(); + //Remove intermediate minor versions from viewable versions + if (versionInfoDeletedEntity.getActiveVersion() != null) { + filter.activeVersion = versionInfoDeletedEntity.getActiveVersion(); + filter.finalVersion = versionInfoDeletedEntity.getLatestFinalVersion(); + viewableVersions.removeIf(filter::isIntermediateMinorVersion); + } + } + } else { + viewableVersions = versionInfoEntity.getViewableVersions(); + //Remove intermediate minor versions from viewable versions + if (versionInfoEntity.getActiveVersion() != null) { + filter.activeVersion = versionInfoEntity.getActiveVersion(); + filter.finalVersion = versionInfoEntity.getLatestFinalVersion(); + viewableVersions.removeIf(filter::isIntermediateMinorVersion); + } + //Add candidate version if available + if (versionInfoEntity.getCandidate() != null) { + viewableVersions.add(versionInfoEntity.getCandidate().getVersion()); + } + } + MDC.put(ActionConstants.TARGET_ENTITY, ActionConstants.TARGET_ENTITY_DB); + ActionUtil.actionLogPostProcessor(StatusCode.COMPLETE, null, "", false); + log.metrics(""); + + log.debug( + "Found " + viewableVersions + " viewable version for action with actionInvariantUUID " + + actionInvariantUuId); + + //Fetch action data for the viewable versions + if (!viewableVersions.isEmpty()) { + ActionUtil.actionLogPreProcessor(ActionSubOperation.GET_ACTIONENTITY_BY_ACTIONINVID, + ActionConstants.TARGET_ENTITY_DB); + Result<ActionEntity> result = + accessor.getActionsByInvId(actionInvariantUuId, viewableVersions); + ActionUtil.actionLogPostProcessor(StatusCode.COMPLETE, null, "", false); + log.metrics(""); + if (result != null) { + actions + .addAll(result.all().stream().map(ActionEntity::toDto).collect(Collectors.toList())); + } + } + } catch (NoHostAvailableException noHostAvailableException) { + logGenericException(noHostAvailableException); + throw new ActionException(ActionErrorConstants.ACTION_INTERNAL_SERVER_ERR_CODE, + ActionErrorConstants.ACTION_ENTITY_INTERNAL_SERVER_ERROR_MSG); + } + log.debug( + " exit getActionsByActionInvariantUUID with actionInvariantUUID= " + actionInvariantUuId); + return actions; + } + + private void logGenericException(Exception exception) { + ActionUtil + .actionLogPostProcessor(StatusCode.ERROR, ActionErrorConstants.ACTION_QUERY_FAILURE_CODE, + ActionErrorConstants.ACTION_ENTITY_INTERNAL_SERVER_ERROR_MSG, false); + log.metrics(""); + ActionUtil.actionErrorLogProcessor( + CategoryLogLevel.FATAL, ActionErrorConstants.ACTION_QUERY_FAILURE_CODE, + ActionErrorConstants.ACTION_QUERY_FAILURE_MSG); + log.error(exception.getMessage()); + } + + + @Override + public List<Action> getFilteredActions(String filterType, String filterId) { + List<Action> actions = new ArrayList<>(); + Result<ActionEntity> result = null; + log.debug( + " entering getFilteredActions By filterType = " + filterType + " With value = " + filterId); + try { + switch (filterType) { + case ActionConstants.FILTER_TYPE_VENDOR: + ActionUtil + .actionLogPreProcessor(ActionSubOperation.GET_ACTIONENTITY_BY_VENDOR, + ActionConstants.TARGET_ENTITY_DB); + result = accessor.getActionsByVendor(filterId); + ActionUtil.actionLogPostProcessor(StatusCode.COMPLETE); + log.metrics(""); + break; + case ActionConstants.FILTER_TYPE_CATEGORY: + ActionUtil.actionLogPreProcessor(ActionSubOperation.GET_ACTIONENTITY_BY_CATEGORY, + ActionConstants.TARGET_ENTITY_DB); + result = accessor.getActionsByCategory(filterId); + ActionUtil.actionLogPostProcessor(StatusCode.COMPLETE); + log.metrics(""); + break; + case ActionConstants.FILTER_TYPE_MODEL: + ActionUtil + .actionLogPreProcessor(ActionSubOperation.GET_ACTIONENTITY_BY_MODEL, + ActionConstants.TARGET_ENTITY_DB); + result = accessor.getActionsByModel(filterId); + ActionUtil.actionLogPostProcessor(StatusCode.COMPLETE); + log.metrics(""); + break; + case ActionConstants.FILTER_TYPE_ECOMP_COMPONENT: + ActionUtil.actionLogPreProcessor(ActionSubOperation.GET_ACTIONENTITY_BY_COMPONENT, + ActionConstants.TARGET_ENTITY_DB); + result = accessor.getActionsByEcompComponent(filterId); + ActionUtil.actionLogPostProcessor(StatusCode.COMPLETE); + log.metrics(""); + break; + case ActionConstants.FILTER_TYPE_NONE: + ActionUtil + .actionLogPreProcessor(ActionSubOperation.GET_ALL_ACTIONS, + ActionConstants.TARGET_ENTITY_DB); + result = accessor.getAllActions(); + ActionUtil.actionLogPostProcessor(StatusCode.COMPLETE); + log.metrics(""); + break; + case ActionConstants.FILTER_TYPE_NAME: + ActionUtil + .actionLogPreProcessor(ActionSubOperation.GET_ACTIONINVID_BY_NAME, + ActionConstants.TARGET_ENTITY_DB); + result = accessor.getInvIdByName(filterId); + ActionUtil.actionLogPostProcessor(StatusCode.COMPLETE); + log.metrics(""); + List<ActionEntity> actionEntities = result.all(); + if (actionEntities != null && !actionEntities.isEmpty()) { + String actionInvariantUuId = actionEntities.get(0).getActionInvariantUuId(); + if (actionInvariantUuId != null) { + return getActionsByActionInvariantUuId(actionInvariantUuId); + } else { + return actions; + } + } + break; + default: + break; + } + if (result != null) { + actions.addAll(result.all().stream().map(ActionEntity::toDto).collect(Collectors.toList())); + } + log.debug( + " exit getFilteredActions By filterType = " + filterType + " With value = " + filterId); + } catch (NoHostAvailableException noHostAvailableException) { + logGenericException(noHostAvailableException); + throw new ActionException(ActionErrorConstants.ACTION_INTERNAL_SERVER_ERR_CODE, + ActionErrorConstants.ACTION_ENTITY_INTERNAL_SERVER_ERROR_MSG); + } + return actions; + } + + @Override + public List<EcompComponent> getEcompComponents() { + List<EcompComponent> ecompComponents = new ArrayList<>(); + Result<EcompComponentEntity> result; + try { + log.debug(" entering getECOMPComponents "); + ActionUtil + .actionLogPreProcessor(ActionSubOperation.GET_ECOMP_COMPONENTS_ENTITY, + ActionConstants.TARGET_ENTITY_DB); + result = accessor.getEcompComponents(); + ActionUtil.actionLogPostProcessor(StatusCode.COMPLETE, null, "", false); + log.metrics(""); + if (result != null) { + ecompComponents.addAll( + result.all().stream().map(EcompComponentEntity::toDto).collect(Collectors.toList())); + } + } catch (NoHostAvailableException noHostAvailableException) { + logGenericException(noHostAvailableException); + throw new ActionException(ActionErrorConstants.ACTION_INTERNAL_SERVER_ERR_CODE, + ActionErrorConstants.ACTION_ENTITY_INTERNAL_SERVER_ERROR_MSG); + } + log.debug(" exit getECOMPComponents "); + return ecompComponents; + } + + @Override + public Action getActionsByActionUuId(String uniqueId) { + try { + log.debug(" entering getActionsByActionUUID with actionUUID= " + uniqueId); + ActionUtil + .actionLogPreProcessor(ActionSubOperation.GET_ACTIONENTITY_BY_ACTIONUUID, + ActionConstants.TARGET_ENTITY_DB); + Result<ActionEntity> result = accessor.actionInvariantUuId(uniqueId); + ActionUtil.actionLogPostProcessor(StatusCode.COMPLETE, null, "", false); + log.metrics(""); + if (result != null) { + log.debug(" exit getActionsByActionUUID with actionUUID= " + uniqueId); + ActionEntity entity = result.one(); + if (entity != null) { + return entity.toDto(); + } + } + log.debug(" exit getActionsByActionUUID with actionUUID= " + uniqueId); + return null; + } catch (NoHostAvailableException noHostAvailableException) { + logGenericException(noHostAvailableException); + throw new ActionException(ActionErrorConstants.ACTION_INTERNAL_SERVER_ERR_CODE, + ActionErrorConstants.ACTION_ENTITY_INTERNAL_SERVER_ERROR_MSG); + } + } + + @Override + public Action getLockedAction(String actionInvariantUuId, String user) throws ActionException { + log.debug(" entering getLockedAction with actionInvariantUUID= " + actionInvariantUuId); + ActionUtil + .actionLogPreProcessor(ActionSubOperation.GET_ACTION_VERSION, + ActionConstants.TARGET_ENTITY_DB); + Action action = null; + VersionInfoEntity versionInfoEntity = versionInfoDao + .get(new VersionInfoEntity(ActionConstants.ACTION_VERSIONABLE_TYPE, actionInvariantUuId)); + ActionUtil.actionLogPostProcessor(StatusCode.COMPLETE, null, "", false); + log.metrics(""); + if (versionInfoEntity != null) { + if (versionInfoEntity.getCandidate() != null) { + String actionUser = versionInfoEntity.getCandidate().getUser(); + if (actionUser != null && actionUser.equals(user)) { + Set<Version> versions = new HashSet<>(); + versions.add(versionInfoEntity.getCandidate().getVersion()); + ActionUtil.actionLogPreProcessor(ActionSubOperation.GET_ACTIONENTITY_BY_ACTIONINVID, + ActionConstants.TARGET_ENTITY_DB); + Result<ActionEntity> result = accessor.getActionsByInvId(actionInvariantUuId, versions); + ActionUtil.actionLogPostProcessor(StatusCode.COMPLETE, null, "", false); + log.metrics(""); + if (result != null) { + ActionEntity actionEntity = result.one(); + action = actionEntity != null ? actionEntity.toDto() : null; + } + } else { + throw new ActionException(ActionErrorConstants.ACTION_ARTIFACT_DEL_LOCKED_OTHER_USER_CODE, + String + .format(ActionErrorConstants.ACTION_ARTIFACT_DEL_LOCKED_OTHER_USER, actionUser)); + } + } else { + throw new ActionException( + ActionErrorConstants.ACTION_NOT_LOCKED_CODE, + ActionErrorConstants.ACTION_NOT_LOCKED_MSG); + } + } else { + throw new ActionException(ActionErrorConstants.ACTION_ENTITY_NOT_EXIST_CODE, + ActionErrorConstants.ACTION_ENTITY_NOT_EXIST); + } + return action; + } + + @Override + protected Mapper<ActionEntity> getMapper() { + return mapper; + } + + + @Override + protected Object[] getKeys(ActionEntity entity) { + return new Object[]{entity.getActionInvariantUuId(), versionMapper.toUDT(entity.getVersion())}; + } + + @Override + public Collection<ActionEntity> list(ActionEntity entity) { + return accessor.getAllActions().all(); + } + + /** + * param actionInvariantUuId. param versions. + */ + private void updateActionStatusForDelete(String actionInvariantUuId, List<Version> versions) { + log.debug( + "entering updateActionStatusForDelete with actionInvariantUUID = " + actionInvariantUuId + + " for versions " + versions); + List<UDTValue> versionUdt = new ArrayList<>(); + + versions.forEach(v -> versionMapper.toUDT(v)); + ActionUtil + .actionLogPreProcessor(ActionSubOperation.UPDATE_ACTION_STATUS, + ActionConstants.TARGET_ENTITY_DB); + + //Update the status column of action table + Statement updateStatusStatement = + QueryBuilder.update("dox", "Action").with(set("status", ActionStatus.Deleted.name())) + .where(eq("actioninvariantuuid", actionInvariantUuId)).and(in("version", versionUdt)); + getSession().execute(updateStatusStatement); + ActionUtil.actionLogPostProcessor(StatusCode.COMPLETE, null, "", false); + log.metrics(""); + //Update the status in the data field of action table + updateStatusInActionData(actionInvariantUuId, versions, ActionStatus.Deleted); + log.debug("exit updateActionStatusForDelete with actionInvariantUUID = " + actionInvariantUuId + + " for versions " + versions); + } + + /** + * Update status for a list of versions for a given action. + * + * @param actionInvariantUuId Invariant UUID of the action. + * @param versions List of {@link Version} for which the status has to be updated. + * @param status The status value. + */ + private void updateStatusInActionData(String actionInvariantUuId, List<Version> versions, + ActionStatus status) { + log.debug("entering updateStatusInActionData for actionInvariantUUID = " + actionInvariantUuId + + " and status = " + status + " for versions " + versions); + for (Version v : versions) { + ActionEntity entity = this.get(new ActionEntity(actionInvariantUuId, v)); + String currentData = entity.getData(); + Map<String, Object> currentDataMap = JsonUtil.json2Object(currentData, LinkedHashMap.class); + currentDataMap.put(ActionConstants.STATUS, status); + String updatedActionData = JsonUtil.object2Json(currentDataMap); + entity.setData(updatedActionData); + this.updateAction(entity.toDto()); + } + log.debug("exit updateStatusInActionData"); + } + + /** + * Get list of all major and minor version values for a given action by action name. + * + * @param name Name of the action + * @return List of {@link Version} objects for the action + */ + private List<Version> getVersionsByName(String name) { + log.debug("entering getVersionsByName for Action Name = " + name); + ActionUtil + .actionLogPreProcessor(ActionSubOperation.GET_ACTION_VERSION, + ActionConstants.TARGET_ENTITY_DB); + Statement statement = + QueryBuilder.select().column("version").from("dox", "Action").where(eq("name", name)); + ResultSet results = getSession().execute(statement); + ActionUtil.actionLogPostProcessor(StatusCode.COMPLETE, null, "", false); + log.metrics(""); + List<Version> versionList = new ArrayList<>(); + for (Row row : results) { + Version version = versionMapper.fromUDT((UDTValue) row.getObject("version")); + versionList.add(version); + } + log.debug("exit getVersionsByName for Action Name = " + name); + return versionList; + } + + @Accessor + interface ActionAccessor { + + @Query("SELECT * FROM Action") + Result<ActionEntity> getAllActions(); + + @Query("SELECT * FROM Action where actionInvariantUuId = ? and version in ? ") + Result<ActionEntity> getActionsByInvId(String actionInvariantUuId, Set<Version> versions); + + @Query("SELECT * FROM Action where supportedModels CONTAINS ?") + Result<ActionEntity> getActionsByModel(String resource); + + @Query("SELECT * FROM Action where supportedComponents CONTAINS ?") + Result<ActionEntity> getActionsByEcompComponent(String resource); + + @Query("SELECT * FROM Action where vendor_list CONTAINS ?") + Result<ActionEntity> getActionsByVendor(String vendor); + + @Query("SELECT * FROM Action where category_list CONTAINS ?") + Result<ActionEntity> getActionsByCategory(String vendor); + + @Query("SELECT actionInvariantUuId FROM Action where name = ? limit 1") + Result<ActionEntity> getInvIdByName(String name); + + @Query("SELECT * FROM ECOMPComponent") + Result<EcompComponentEntity> getEcompComponents(); + + @Query("SELECT * FROM Action where actionUUID = ?") + Result<ActionEntity> actionInvariantUuId(String actionUuId); + + } + + class VersionPredicate { + Version activeVersion; + Version finalVersion; + + public boolean isIntermediateMinorVersion(Version version) { + int activeMajorVersion = activeVersion.getMajor(); + int activeMinorVersion = activeVersion.getMinor(); + int currentMinorVersion = version.getMinor(); + int currentMajorVersion = version.getMajor(); + + if (finalVersion != null) { + if (finalVersion.getMajor() == activeMajorVersion + && currentMajorVersion == finalVersion.getMajor()) { + if (currentMinorVersion < activeMinorVersion && currentMinorVersion != 0) { + return true; + } + } else { + return false; + } + } else { + if (!version.equals(activeVersion)) { + return true; + } + } + + return false; + } + + } +} diff --git a/openecomp-be/lib/openecomp-sdc-action-lib/pom.xml b/openecomp-be/lib/openecomp-sdc-action-lib/pom.xml new file mode 100644 index 0000000000..7ff15d6bce --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-action-lib/pom.xml @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.openecomp.sdc</groupId> + <artifactId>openecomp-sdc-lib</artifactId> + <version>1.0.0-SNAPSHOT</version> + </parent> + + <artifactId>openecomp-sdc-action-lib</artifactId> + <packaging>pom</packaging> + + + + + <modules> + <module>openecomp-sdc-action-api</module> + <module>openecomp-sdc-action-core</module> + </modules> + + +</project>
\ No newline at end of file |