aboutsummaryrefslogtreecommitdiffstats
path: root/workflow-designer-be
diff options
context:
space:
mode:
Diffstat (limited to 'workflow-designer-be')
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/Sorting.java33
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/VersionStatesFormatter.java11
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionStateModificationException.java7
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerImpl.java13
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/types/PagingConstants.java4
-rw-r--r--workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/types/SortingTest.java15
-rw-r--r--workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/types/VersionStatesFormatterTest.java2
7 files changed, 60 insertions, 25 deletions
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/Sorting.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/Sorting.java
index 1a0c1a15..38b579b2 100644
--- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/Sorting.java
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/Sorting.java
@@ -23,27 +23,44 @@ import java.util.Objects;
import java.util.stream.Collectors;
import lombok.Getter;
import org.onap.sdc.workflow.services.types.Sort;
+import org.openecomp.sdc.logging.api.Logger;
+import org.openecomp.sdc.logging.api.LoggerFactory;
@Getter
public class Sorting {
private static final String SORTS_DELIMITER = ",";
private static final String DIRECTION_DELIMITER = ":";
- private static final String ASCENDING_ORDER = "asc";
+ private static final String ASC = "asc";
+ private static final String DESC = "desc";
+ private static final Logger LOGGER = LoggerFactory.getLogger(Sorting.class);
private List<Sort> sorts = Collections.emptyList();
public void setSort(String sortString) {
- this.sorts = Arrays.stream(sortString.split(SORTS_DELIMITER)).map(Sorting::formatSort).filter(Objects::nonNull)
- .collect(Collectors.toList());
+ this.sorts = Arrays.stream(sortString.split(SORTS_DELIMITER))
+ .map(Sorting::formatSort)
+ .filter(Objects::nonNull)
+ .collect(Collectors.toList());
}
private static Sort formatSort(String sort) {
- String[] tokens = sort.split(DIRECTION_DELIMITER);
- try {
- return new Sort(tokens[0], ASCENDING_ORDER.equalsIgnoreCase(tokens[1]));
- } catch (Exception e) {
- return null;
+ String[] tokens = sort.split(DIRECTION_DELIMITER, 2);
+
+ return tokens.length == 2
+ ? formatSingleSort(tokens[0], tokens[1])
+ : new Sort(tokens[0], true);
+ }
+
+ private static Sort formatSingleSort(String property, String direction) {
+ if (ASC.equalsIgnoreCase(direction)) {
+ return new Sort(property, true);
+ }
+ if (DESC.equalsIgnoreCase(direction)) {
+ return new Sort(property, false);
}
+ LOGGER.warn("Sorting direction {} of property {} is invalid. Allowed direction values: asc, desc.", direction,
+ property);
+ return null;
}
}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/VersionStatesFormatter.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/VersionStatesFormatter.java
index 51e75edf..ebc7d693 100644
--- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/VersionStatesFormatter.java
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/VersionStatesFormatter.java
@@ -37,16 +37,17 @@ public class VersionStatesFormatter {
}
public void setState(String value) {
- this.versionStates = formatString(value);
+ setVersionState(value);
}
private static Set<WorkflowVersionState> formatString(String value) {
try {
return value == null ? null : Arrays.stream(value.split(",")).map(WorkflowVersionState::valueOf)
- .collect(Collectors.toSet());
- } catch (Exception ignore) {
- LOGGER.info(
- "value is invalid and cannot be formatted to a set of version states, therefore it set to empty set");
+ .collect(Collectors.toSet());
+ } catch (IllegalArgumentException ex) {
+ LOGGER.warn(String.format(
+ "value %s is invalid and cannot be formatted to a set of version states, therefore it set to empty set",
+ value), ex);
return Collections.emptySet();
}
}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionStateModificationException.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionStateModificationException.java
index 011b2746..379d8e2e 100644
--- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionStateModificationException.java
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionStateModificationException.java
@@ -22,7 +22,12 @@ public class VersionStateModificationException extends RuntimeException {
public VersionStateModificationException(String workflowId, String versionId, WorkflowVersionState sourceState,
WorkflowVersionState targetState) {
+ this(workflowId, versionId, sourceState, targetState, null);
+ }
+
+ public VersionStateModificationException(String workflowId, String versionId, WorkflowVersionState sourceState,
+ WorkflowVersionState targetState, Exception submitException) {
super(String.format("Workflow %s, version %s: state can not be changed from %s to %s", workflowId, versionId,
- sourceState.name(), targetState.name()));
+ sourceState.name(), targetState.name()), submitException);
}
}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerImpl.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerImpl.java
index 14a6722e..75629d0b 100644
--- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerImpl.java
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerImpl.java
@@ -34,8 +34,6 @@ import org.onap.sdc.workflow.persistence.ParameterRepository;
import org.onap.sdc.workflow.persistence.types.ArtifactEntity;
import org.onap.sdc.workflow.persistence.types.ParameterEntity;
import org.onap.sdc.workflow.persistence.types.ParameterRole;
-import org.onap.sdc.workflow.services.types.WorkflowVersion;
-import org.onap.sdc.workflow.services.types.WorkflowVersionState;
import org.onap.sdc.workflow.services.WorkflowVersionManager;
import org.onap.sdc.workflow.services.exceptions.EntityNotFoundException;
import org.onap.sdc.workflow.services.exceptions.InvalidArtifactException;
@@ -44,6 +42,8 @@ import org.onap.sdc.workflow.services.exceptions.VersionModificationException;
import org.onap.sdc.workflow.services.exceptions.VersionStateModificationException;
import org.onap.sdc.workflow.services.impl.mappers.VersionMapper;
import org.onap.sdc.workflow.services.impl.mappers.VersionStateMapper;
+import org.onap.sdc.workflow.services.types.WorkflowVersion;
+import org.onap.sdc.workflow.services.types.WorkflowVersionState;
import org.openecomp.sdc.logging.api.Logger;
import org.openecomp.sdc.logging.api.LoggerFactory;
import org.openecomp.sdc.versioning.VersioningManager;
@@ -158,15 +158,14 @@ public class WorkflowVersionManagerImpl implements WorkflowVersionManager {
@Override
public void updateState(String workflowId, String versionId, WorkflowVersionState state) {
- WorkflowVersionState retrievedState =
- versionStateMapper.versionStatusToWorkflowVersionState(getVersion(workflowId, versionId).getStatus());
-
+ WorkflowVersionState retrievedState = getState(workflowId, versionId);
if (state == CERTIFIED) {
try {
versioningManager.submit(workflowId, new Version(versionId),
String.format("Update version state to %s", state.name()));
- } catch (Exception e) {
- throw new VersionStateModificationException(workflowId, versionId, retrievedState, state);
+ } catch (Exception submitException) {
+ throw new VersionStateModificationException(workflowId, versionId, retrievedState,
+ state, submitException);
}
} else {
throw new VersionStateModificationException(workflowId, versionId, retrievedState, state);
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/types/PagingConstants.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/types/PagingConstants.java
index dd6eefad..f92abf6b 100644
--- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/types/PagingConstants.java
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/types/PagingConstants.java
@@ -5,4 +5,8 @@ public class PagingConstants {
public static final int DEFAULT_OFFSET = 0;
public static final int DEFAULT_LIMIT = 200;
public static final int MAX_LIMIT = 2000;
+
+ private PagingConstants() {
+ throw new IllegalStateException("Constants class");
+ }
}
diff --git a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/types/SortingTest.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/types/SortingTest.java
index 29436449..4aefad4f 100644
--- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/types/SortingTest.java
+++ b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/types/SortingTest.java
@@ -18,11 +18,17 @@ public class SortingTest {
@Test
public void setSortInvalid() {
- sorting.setSort("a");
+ sorting.setSort("name:asc:a,:,");
assertEquals(Collections.emptyList(), sorting.getSorts());
}
@Test
+ public void setSortAscByDefault() {
+ sorting.setSort("name");
+ assertEquals(Collections.singletonList(new Sort("name", true)), sorting.getSorts());
+ }
+
+ @Test
public void setSortAsc() {
sorting.setSort("name:asc");
assertEquals(Collections.singletonList(new Sort("name", true)), sorting.getSorts());
@@ -36,7 +42,10 @@ public class SortingTest {
@Test
public void setSortMoreThanOne() {
- sorting.setSort("name:asc,date:desc");
- assertEquals(Arrays.asList(new Sort("name", true), new Sort("date", false)), sorting.getSorts());
+ sorting.setSort("name:asc,type,date:desc");
+ assertEquals(Arrays.asList(
+ new Sort("name", true),
+ new Sort("type", true),
+ new Sort("date", false)), sorting.getSorts());
}
} \ No newline at end of file
diff --git a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/types/VersionStatesFormatterTest.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/types/VersionStatesFormatterTest.java
index c40aef3e..c4c6fbea 100644
--- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/types/VersionStatesFormatterTest.java
+++ b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/types/VersionStatesFormatterTest.java
@@ -21,7 +21,7 @@ public class VersionStatesFormatterTest {
@Test
public void setVersionStateInvalid() {
- versionStateSet.setVersionState("aaa");
+ versionStateSet.setVersionState(",,a");
assertEquals(Collections.emptySet() ,versionStateSet.getVersionStates());
}