summaryrefslogtreecommitdiffstats
path: root/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be
diff options
context:
space:
mode:
authorsheetalm <sheetal.mudholkar@amdocs.com>2018-04-12 13:20:36 +0530
committerVitaly Emporopulo <Vitaliy.Emporopulo@amdocs.com>2018-04-12 16:21:28 +0000
commit894285bfa9ccacde35b1e94e07856b53971e2559 (patch)
treed7174842de984017163eeec5834d34bc46db7cd3 /services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be
parentd60b2a40c15c5952f8a31e2d2aa4be2cf4837fc8 (diff)
Activity Spec - change in package and group names
1 Package structure will now be org.onap.sdc.activityspec instead of org.openecomp.activityspec 2 Same applies for group names 3 This is done to fix issue with pushing docker images to nexus repository 4 In ONAP in order for you to push to nexus you need to match the package and artifact name to the repository Change-Id: I1266c66fa0d0a85acd9ca1164647b996433eb960 Issue-ID: SDC-1048 Signed-off-by: sheetalm <sheetal.mudholkar@amdocs.com>
Diffstat (limited to 'services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be')
-rw-r--r--services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/ActivitySpecManager.java36
-rw-r--r--services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/dao/ActivitySpecDao.java27
-rw-r--r--services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/dao/impl/ActivitySpecDaoZusammenImpl.java155
-rw-r--r--services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/dao/types/ActivitySpecEntity.java39
-rw-r--r--services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/datatypes/ActivitySpecData.java29
-rw-r--r--services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/datatypes/ActivitySpecParameter.java34
-rw-r--r--services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/datatypes/ElementType.java21
-rw-r--r--services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/datatypes/ItemType.java21
-rw-r--r--services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/impl/ActivitySpecManagerImpl.java291
9 files changed, 0 insertions, 653 deletions
diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/ActivitySpecManager.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/ActivitySpecManager.java
deleted file mode 100644
index 4fa41d029a..0000000000
--- a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/ActivitySpecManager.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright © 2016-2017 European Support Limited
- *
- * 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.
- */
-
-package org.openecomp.activityspec.be;
-
-import java.util.Collection;
-
-import org.openecomp.activityspec.api.rest.types.ActivitySpecAction;
-import org.openecomp.activityspec.be.dao.types.ActivitySpecEntity;
-import org.openecomp.sdc.versioning.types.Item;
-
-public interface ActivitySpecManager {
-
- ActivitySpecEntity createActivitySpec(ActivitySpecEntity activitySpecEntity);
-
- ActivitySpecEntity get(ActivitySpecEntity activitySpec);
-
- void update(ActivitySpecEntity activitySpec);
-
- void actOnAction(String activitySpecId, String versionId, ActivitySpecAction action);
-
- Collection<Item> list(String versionStatus);
-}
diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/dao/ActivitySpecDao.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/dao/ActivitySpecDao.java
deleted file mode 100644
index 375adac876..0000000000
--- a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/dao/ActivitySpecDao.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright © 2016-2017 European Support Limited
- *
- * 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.
- */
-
-package org.openecomp.activityspec.be.dao;
-
-import org.openecomp.activityspec.be.dao.types.ActivitySpecEntity;
-
-public interface ActivitySpecDao {
- void create(ActivitySpecEntity activitySpecEntity);
-
- ActivitySpecEntity get(ActivitySpecEntity activitySpec);
-
- void update(ActivitySpecEntity activitySpec);
-}
diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/dao/impl/ActivitySpecDaoZusammenImpl.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/dao/impl/ActivitySpecDaoZusammenImpl.java
deleted file mode 100644
index 0dabcca984..0000000000
--- a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/dao/impl/ActivitySpecDaoZusammenImpl.java
+++ /dev/null
@@ -1,155 +0,0 @@
-/*
- * Copyright © 2016-2017 European Support Limited
- *
- * 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.
- */
-
-package org.openecomp.activityspec.be.dao.impl;
-
-import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element;
-import com.amdocs.zusammen.adaptor.inbound.api.types.item.ZusammenElement;
-import com.amdocs.zusammen.datatypes.SessionContext;
-import com.amdocs.zusammen.datatypes.item.Action;
-import com.amdocs.zusammen.datatypes.item.ElementContext;
-import com.amdocs.zusammen.datatypes.item.Info;
-
-import org.openecomp.activityspec.be.dao.ActivitySpecDao;
-import org.openecomp.activityspec.be.dao.types.ActivitySpecEntity;
-import org.openecomp.activityspec.utils.ActivitySpecConstant;
-import org.openecomp.activityspec.be.datatypes.ActivitySpecData;
-import org.openecomp.activityspec.be.datatypes.ElementType;
-import org.openecomp.core.utilities.json.JsonUtil;
-import org.openecomp.core.zusammen.api.ZusammenAdaptor;
-
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
-import java.util.Objects;
-import java.util.Optional;
-
-import static org.openecomp.core.zusammen.api.ZusammenUtil.buildStructuralElement;
-import static org.openecomp.core.zusammen.api.ZusammenUtil.createSessionContext;
-
-public class ActivitySpecDaoZusammenImpl implements ActivitySpecDao {
-
- private final ZusammenAdaptor zusammenAdaptor;
-
- public ActivitySpecDaoZusammenImpl(ZusammenAdaptor zusammenAdaptor) {
- this.zusammenAdaptor = zusammenAdaptor;
- }
-
- @Override
- public void create(ActivitySpecEntity entity) {
- SessionContext context = createSessionContext();
- ZusammenElement generalElement = mapActivityDetailsToZusammenElement(entity, Action.CREATE);
-
- ElementContext elementContext =
- new ElementContext(entity.getId(), entity.getVersion().getId());
- zusammenAdaptor.saveElement(context, elementContext, generalElement,
- "Create Activity Spec General Info Element");
- }
-
- @Override
- public ActivitySpecEntity get(ActivitySpecEntity entity) {
- SessionContext context = createSessionContext();
-
- ElementContext elementContext = new ElementContext(entity.getId(), entity.getVersion().getId());
- Optional<Element> element = zusammenAdaptor.getElementByName(context, elementContext,
- null, ElementType.ACTIVITYSPEC.name());
- if (element.isPresent()) {
- return mapZusammenElementToActivityDetails(element.get());
- } else {
- return null;
- }
- }
-
- @Override
- public void update(ActivitySpecEntity entity) {
- SessionContext context = createSessionContext();
- ZusammenElement generalElement = mapActivityDetailsToZusammenElement(entity, Action.UPDATE);
-
- ElementContext elementContext =
- new ElementContext(entity.getId(), entity.getVersion().getId());
- zusammenAdaptor.saveElement(context, elementContext, generalElement,
- "Update Activity Spec General Info Element");
- }
-
-
- private ActivitySpecEntity mapZusammenElementToActivityDetails(Element element) {
- ActivitySpecEntity entity = new ActivitySpecEntity();
- entity.setId(element.getElementId().getValue());
- enrichEntityFromElementData(entity, element.getData());
- enrichEntityFromElementInfo(entity, element.getInfo());
- return entity;
- }
-
- private ZusammenElement mapActivityDetailsToZusammenElement(ActivitySpecEntity entity,
- Action action) {
- ZusammenElement generalElement =
- buildStructuralElement(ElementType.ACTIVITYSPEC.name(), action);
-
- enrichElementInfoFromEntity(generalElement, entity);
- enrichElementDataFromEntity(generalElement, entity);
- return generalElement;
- }
-
-
- private void enrichEntityFromElementInfo(ActivitySpecEntity entity, Info info) {
- entity.setName(info.getProperty(InfoPropertyName.NAME.getValue()));
- entity.setDescription(info.getProperty(InfoPropertyName.DESCRIPTION.getValue()));
- entity.setCategoryList(info.getProperty(InfoPropertyName.CATEGORY.getValue()));
- }
-
- private void enrichEntityFromElementData(ActivitySpecEntity entity, InputStream data) {
- ActivitySpecData activitySpecData = JsonUtil.json2Object(data, ActivitySpecData.class);
- if (Objects.nonNull(activitySpecData)) {
- entity.setInputs(activitySpecData.getInputs());
- entity.setOutputs(activitySpecData.getOutputs());
- entity.setType(activitySpecData.getType());
- entity.setContent(activitySpecData.getContent());
- }
- }
-
- private void enrichElementInfoFromEntity(ZusammenElement element, ActivitySpecEntity entity) {
- element.getInfo().addProperty(InfoPropertyName.DESCRIPTION.getValue(), entity.getDescription());
- element.getInfo().addProperty(InfoPropertyName.NAME.getValue(), entity.getName());
- element.getInfo().addProperty(InfoPropertyName.CATEGORY.getValue(),
- entity.getCategoryList());
- }
-
-
- private void enrichElementDataFromEntity(ZusammenElement element, ActivitySpecEntity entity) {
- ActivitySpecData activitySpecData = new ActivitySpecData();
- activitySpecData.setInputs(entity.getInputs());
- activitySpecData.setOutputs(entity.getOutputs());
- activitySpecData.setType(entity.getType());
- activitySpecData.setContent(entity.getContent());
- element.setData(new ByteArrayInputStream(JsonUtil.object2Json(activitySpecData).getBytes()));
- }
-
- public enum InfoPropertyName {
- DESCRIPTION("description"),
- NAME("name"),
- CATEGORY(ActivitySpecConstant.CATEGORY_ATTRIBUTE_NAME);
-
- private final String value;
-
- InfoPropertyName(String value) {
- this.value = value;
- }
-
- public String getValue() {
- return value;
- }
- }
-
-}
diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/dao/types/ActivitySpecEntity.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/dao/types/ActivitySpecEntity.java
deleted file mode 100644
index 2f261f8fa9..0000000000
--- a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/dao/types/ActivitySpecEntity.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright © 2016-2017 European Support Limited
- *
- * 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.
- */
-
-package org.openecomp.activityspec.be.dao.types;
-
-import org.openecomp.activityspec.be.datatypes.ActivitySpecParameter;
-import org.openecomp.sdc.versioning.dao.types.Version;
-
-import java.util.List;
-
-@lombok.Data
-public class ActivitySpecEntity {
- private String id;
- private Version version;
- private String name;
- private String description;
-
- private List<String> categoryList;
- private List<ActivitySpecParameter> inputs;
- private List<ActivitySpecParameter> outputs;
- private String type;
- private String content;
-
- //Not to be maintained in activityspec element
- private String status;
-}
diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/datatypes/ActivitySpecData.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/datatypes/ActivitySpecData.java
deleted file mode 100644
index ad70376aa2..0000000000
--- a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/datatypes/ActivitySpecData.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright © 2016-2018 European Support Limited
- *
- * 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.
- */
-
-package org.openecomp.activityspec.be.datatypes;
-
-import java.util.Collections;
-import java.util.List;
-
-@lombok.Data
-public class ActivitySpecData {
- private List<ActivitySpecParameter> inputs = Collections.emptyList();
- private List<ActivitySpecParameter> outputs = Collections.emptyList();
- private String type;
- private String content;
-}
-
diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/datatypes/ActivitySpecParameter.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/datatypes/ActivitySpecParameter.java
deleted file mode 100644
index b9153fa5d9..0000000000
--- a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/datatypes/ActivitySpecParameter.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright © 2016-2018 European Support Limited
- *
- * 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.
- */
-
-package org.openecomp.activityspec.be.datatypes;
-
-@lombok.Data
-public class ActivitySpecParameter {
- private String name;
- private String type;
- private String value;
-
- @SuppressWarnings("unused")
- public ActivitySpecParameter() {
- // default constructor for automatic tools that use reflection
- }
-
- public ActivitySpecParameter(String name, String type) {
- this.name = name;
- this.type = type;
- }
-}
diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/datatypes/ElementType.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/datatypes/ElementType.java
deleted file mode 100644
index be7e61ca8c..0000000000
--- a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/datatypes/ElementType.java
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * Copyright © 2016-2018 European Support Limited
- *
- * 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.
- */
-
-package org.openecomp.activityspec.be.datatypes;
-
-public enum ElementType {
- ACTIVITYSPEC;
-}
diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/datatypes/ItemType.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/datatypes/ItemType.java
deleted file mode 100644
index 5091412d08..0000000000
--- a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/datatypes/ItemType.java
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * Copyright © 2016-2018 European Support Limited
- *
- * 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.
- */
-
-package org.openecomp.activityspec.be.datatypes;
-
-public enum ItemType {
- ACTIVITYSPEC
-}
diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/impl/ActivitySpecManagerImpl.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/impl/ActivitySpecManagerImpl.java
deleted file mode 100644
index 44383734e8..0000000000
--- a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/impl/ActivitySpecManagerImpl.java
+++ /dev/null
@@ -1,291 +0,0 @@
-/*
- * Copyright © 2016-2017 European Support Limited
- *
- * 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.
- */
-
-package org.openecomp.activityspec.be.impl;
-
-import static org.openecomp.activityspec.api.rest.types.ActivitySpecAction.CERTIFY;
-import static org.openecomp.activityspec.api.rest.types.ActivitySpecAction.DELETE;
-import static org.openecomp.activityspec.api.rest.types.ActivitySpecAction.DEPRECATE;
-import static org.openecomp.activityspec.utils.ActivitySpecConstant.ACTIVITY_SPEC_NOT_FOUND;
-import static org.openecomp.activityspec.utils.ActivitySpecConstant.INVALID_STATE;
-import static org.openecomp.sdc.versioning.dao.types.VersionStatus.Certified;
-import static org.openecomp.sdc.versioning.dao.types.VersionStatus.Deleted;
-import static org.openecomp.sdc.versioning.dao.types.VersionStatus.Deprecated;
-import static org.openecomp.sdc.versioning.dao.types.VersionStatus.Draft;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.EnumMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.function.Predicate;
-import org.openecomp.activityspec.api.rest.types.ActivitySpecAction;
-import org.openecomp.activityspec.be.ActivitySpecManager;
-import org.openecomp.activityspec.be.dao.ActivitySpecDao;
-import org.openecomp.activityspec.be.dao.types.ActivitySpecEntity;
-import org.openecomp.activityspec.be.datatypes.ItemType;
-import org.openecomp.activityspec.errors.ActivitySpecNotFoundException;
-import org.openecomp.activityspec.utils.ActivitySpecConstant;
-import org.openecomp.core.dao.UniqueValueDao;
-import org.openecomp.core.util.UniqueValueUtil;
-import org.openecomp.sdc.common.errors.CoreException;
-import org.openecomp.sdc.common.errors.ErrorCategory;
-import org.openecomp.sdc.common.errors.ErrorCode;
-import org.openecomp.sdc.common.errors.SdcRuntimeException;
-import org.openecomp.sdc.logging.api.Logger;
-import org.openecomp.sdc.logging.api.LoggerFactory;
-import org.openecomp.sdc.versioning.ItemManager;
-import org.openecomp.sdc.versioning.VersioningManager;
-import org.openecomp.sdc.versioning.dao.types.Version;
-import org.openecomp.sdc.versioning.dao.types.VersionStatus;
-import org.openecomp.sdc.versioning.types.Item;
-import org.openecomp.sdc.versioning.types.VersionCreationMethod;
-
-public class ActivitySpecManagerImpl implements ActivitySpecManager {
-
- private static final Map<VersionStatus, Transition> TRANSITIONS;
-
- static {
- TRANSITIONS = new EnumMap<>(VersionStatus.class);
- TRANSITIONS.put(Certified, new Transition("Certify", Draft));
- TRANSITIONS.put(Deprecated, new Transition("Deprecate", Certified));
- TRANSITIONS.put(Deleted, new Transition("Delete", Deprecated));
- }
-
- private final ItemManager itemManager;
- private final VersioningManager versioningManager;
- private final ActivitySpecDao activitySpecDao;
- private final UniqueValueUtil uniqueValueUtil;
- private static final String ACTIVITY_SPEC_NAME = "ActivitySpec.Name";
- private static final Logger LOGGER =
- LoggerFactory.getLogger(ActivitySpecManagerImpl.class);
-
- public ActivitySpecManagerImpl(ItemManager itemManager,
- VersioningManager versioningManager,
- ActivitySpecDao activitySpecDao,
- UniqueValueDao uniqueValueDao) {
- this.itemManager = itemManager;
- this.versioningManager = versioningManager;
- this.activitySpecDao = activitySpecDao;
- this.uniqueValueUtil = new UniqueValueUtil(uniqueValueDao);
- }
-
- @Override
- public ActivitySpecEntity createActivitySpec(ActivitySpecEntity activitySpecEntity) {
-
- validateUniqueValue(activitySpecEntity);
-
- Item item = getActivitySpecItem(activitySpecEntity);
- item = itemManager.create(item);
-
- Version version = getActivitySpecVersion(activitySpecEntity);
- versioningManager.create(item.getId(), version, VersionCreationMethod.major);
-
- enrichActivitySpec(item, version, activitySpecEntity);
- activitySpecDao.create(activitySpecEntity);
-
- uniqueValueUtil.createUniqueValue(ACTIVITY_SPEC_NAME, activitySpecEntity.getName());
- return activitySpecEntity;
- }
-
- private void validateUniqueValue(ActivitySpecEntity activitySpecEntity) {
- try {
- uniqueValueUtil.validateUniqueValue(ACTIVITY_SPEC_NAME, activitySpecEntity.getName());
- } catch (CoreException exception) {
- LOGGER.debug("Unique value error for activity spec name :" + activitySpecEntity.getName(), exception);
- throw new CoreException(new ErrorCode.ErrorCodeBuilder()
- .withCategory(ErrorCategory.APPLICATION)
- .withId(exception.code().id())
- .withMessage("name already in use").build());
- }
- }
-
- private Version getActivitySpecVersion(ActivitySpecEntity activitySpecEntity) {
- return activitySpecEntity.getVersion() == null ? new Version()
- : activitySpecEntity.getVersion();
-
- }
-
- @Override
- public ActivitySpecEntity get(ActivitySpecEntity activitySpec) {
- activitySpec.setVersion(calculateLatestVersion(activitySpec.getId(),activitySpec.getVersion()));
- ActivitySpecEntity retrieved;
- try {
- retrieved = activitySpecDao.get(activitySpec);
- } catch (SdcRuntimeException runtimeException) {
- LOGGER.debug("Failed to retrieve activity spec for activitySpecId: " + activitySpec.getId()
- + " and version: " + activitySpec.getVersion().getId(), runtimeException);
- throw new ActivitySpecNotFoundException(ACTIVITY_SPEC_NOT_FOUND, runtimeException);
- }
- if (retrieved != null) {
- final Version retrievedVersion = versioningManager.get(activitySpec.getId(),
- activitySpec.getVersion());
- retrieved.setStatus(Objects.nonNull(retrievedVersion) ? retrievedVersion.getStatus().name()
- : null);
- }
- return retrieved;
- }
-
- @Override
- public void update(ActivitySpecEntity activitySpec) {
-
- ActivitySpecEntity previousActivitySpec = get(activitySpec);
-
- if (!activitySpec.getName().equals(previousActivitySpec.getName())) {
- validateUniqueValue(activitySpec);
- }
-
- activitySpecDao.update(activitySpec);
-
- if (!activitySpec.getName().equals(previousActivitySpec.getName())) {
- uniqueValueUtil.createUniqueValue(ACTIVITY_SPEC_NAME, activitySpec.getName());
- itemManager.updateName(activitySpec.getId(), activitySpec.getName());
- uniqueValueUtil.deleteUniqueValue(ACTIVITY_SPEC_NAME, previousActivitySpec.getName());
- }
- }
-
- @Override
- public void actOnAction(String activitySpecId, String versionId, ActivitySpecAction action) {
- Version version = new Version(versionId);
- version = calculateLatestVersion(activitySpecId, version);
- if (action == CERTIFY) {
- version.setStatus(Certified);
- }
- if (action == DEPRECATE) {
- version.setStatus(Deprecated);
- }
- if (action == DELETE) {
- version.setStatus(Deleted);
- }
-
- updateVersionStatus(activitySpecId, action, version);
- if (action == DELETE) {
- ActivitySpecEntity entity = new ActivitySpecEntity();
- entity.setId(activitySpecId);
- entity.setVersion(version);
- final ActivitySpecEntity activitySpecEntity = get(entity);
- uniqueValueUtil.deleteUniqueValue(ACTIVITY_SPEC_NAME, activitySpecEntity.getName());
- }
- }
-
- private void updateVersionStatus(String activitySpecId, ActivitySpecAction action,
- Version version) {
- VersionStatus prevVersionStatus = null;
- Version retrievedVersion;
- try {
- retrievedVersion = versioningManager.get(activitySpecId, version);
- } catch (SdcRuntimeException exception) {
- LOGGER.debug("Failed to get version for activitySpecId: " + activitySpecId
- + " and version: " + version.getId(), exception);
- throw new ActivitySpecNotFoundException(ACTIVITY_SPEC_NOT_FOUND, exception);
-
- }
-
- VersionStatus status = version.getStatus();
- Transition transition = TRANSITIONS.get(status);
- if (transition != null) {
-
- VersionStatus retrievedStatus = Objects.nonNull(retrievedVersion) ? retrievedVersion.getStatus() : null;
- if (retrievedStatus != transition.prevStatus) {
- LOGGER.debug("Failed to " + version.getStatus() + " since activity spec is in "
- + retrievedStatus);
- throw new CoreException(new ErrorCode.ErrorCodeBuilder()
- .withMessage(INVALID_STATE).build());
- }
- prevVersionStatus = transition.prevStatus;
- }
-
- if (Objects.nonNull(retrievedVersion)) {
- retrievedVersion.setStatus(status);
- versioningManager.updateVersion(activitySpecId, retrievedVersion);
- itemManager.updateVersionStatus(activitySpecId, status, prevVersionStatus);
- versioningManager.publish(activitySpecId, retrievedVersion, "actionOnActivitySpec :"
- + action.name());
- }
- }
-
- private Version calculateLatestVersion(String activitySpecId, Version version) {
- if (ActivitySpecConstant.VERSION_ID_DEFAULT_VALUE.equalsIgnoreCase(version.getId())) {
- List<Version> list;
- try {
- list = versioningManager.list(activitySpecId);
- } catch (SdcRuntimeException runtimeException) {
- LOGGER.debug("Failed to list versions for activitySpecId "
- + activitySpecId, runtimeException);
- throw new ActivitySpecNotFoundException(ACTIVITY_SPEC_NOT_FOUND, runtimeException);
- }
- if (Objects.nonNull(list) && !list.isEmpty()) {
- return list.get(0);
- }
- }
- return version;
- }
-
- @Override
- public Collection<Item> list(String versionStatus) {
- Predicate<Item> itemPredicate;
- if (Objects.nonNull(versionStatus)) {
-
- VersionStatus statusEnumValue;
-
- try {
- statusEnumValue = VersionStatus.valueOf(versionStatus);
- } catch (IllegalArgumentException e) {
- LOGGER.debug("Unexpected value of VersionStatus {}", versionStatus);
- return Collections.emptyList();
- }
-
- itemPredicate = item -> ItemType.ACTIVITYSPEC.name().equals(item.getType())
- && item.getVersionStatusCounters().containsKey(statusEnumValue);
-
- } else {
- itemPredicate = item -> ItemType.ACTIVITYSPEC.name().equals(item.getType());
- }
-
- return itemManager.list(itemPredicate);
- }
-
- private void enrichActivitySpec(Item item, Version version,
- ActivitySpecEntity activitySpecEntity) {
- activitySpecEntity.setId(item.getId());
- activitySpecEntity.setVersion(version);
- }
-
- private Item getActivitySpecItem(ActivitySpecEntity activitySpecEntity) {
- Item item = new Item();
- item.setType(ItemType.ACTIVITYSPEC.name());
- item.setName(activitySpecEntity.getName());
- if (activitySpecEntity.getId() != null) {
- item.setId(activitySpecEntity.getId());
- }
- item.addProperty(ActivitySpecConstant.CATEGORY_ATTRIBUTE_NAME,
- activitySpecEntity.getCategoryList());
- return item;
- }
-
- private static class Transition {
-
- private final String action;
- private final VersionStatus prevStatus;
-
- private Transition(String action, VersionStatus prevStatus) {
- this.action = action;
- this.prevStatus = prevStatus;
- }
- }
-
-}