Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormegumi.telles2018-03-27 20:54:56 +0000
committermegumi.telles2018-03-28 14:43:38 +0000
commitbc9bca5402f32a8b808f2d3517de0c5dcb910c79 (patch)
treec4a6adc22c69e1581b847a1f95232c85611570be
parent85308c8df81958f2bdfd8f3b069c3a809cce31d9 (diff)
downloadorg.eclipse.osee-bc9bca5402f32a8b808f2d3517de0c5dcb910c79.tar.gz
org.eclipse.osee-bc9bca5402f32a8b808f2d3517de0c5dcb910c79.tar.xz
org.eclipse.osee-bc9bca5402f32a8b808f2d3517de0c5dcb910c79.zip
feature: Add support for create/update discrepancy
-rw-r--r--plugins/org.eclipse.osee.disposition.rest.model/src/org/eclipse/osee/disposition/model/CiTestPoint.java20
-rw-r--r--plugins/org.eclipse.osee.disposition.rest/src/org/eclipse/osee/disposition/rest/DispoApi.java7
-rw-r--r--plugins/org.eclipse.osee.disposition.rest/src/org/eclipse/osee/disposition/rest/internal/DispoApiImpl.java84
-rw-r--r--plugins/org.eclipse.osee.disposition.rest/src/org/eclipse/osee/disposition/rest/internal/DispoConnector.java24
-rw-r--r--plugins/org.eclipse.osee.disposition.rest/src/org/eclipse/osee/disposition/rest/resources/ContinuousIntegrationResource.java29
-rw-r--r--plugins/org.eclipse.osee.disposition.rest/src/org/eclipse/osee/disposition/rest/util/DispoUtil.java56
6 files changed, 199 insertions, 21 deletions
diff --git a/plugins/org.eclipse.osee.disposition.rest.model/src/org/eclipse/osee/disposition/model/CiTestPoint.java b/plugins/org.eclipse.osee.disposition.rest.model/src/org/eclipse/osee/disposition/model/CiTestPoint.java
index fb7a963853..71dbd53627 100644
--- a/plugins/org.eclipse.osee.disposition.rest.model/src/org/eclipse/osee/disposition/model/CiTestPoint.java
+++ b/plugins/org.eclipse.osee.disposition.rest.model/src/org/eclipse/osee/disposition/model/CiTestPoint.java
@@ -10,23 +10,23 @@ import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "CiTestPoint")
public class CiTestPoint {
- private String passing;
- private String failing;
+ private String pass;
+ private String fail;
- public String getPassing() {
- return passing;
+ public String getPass() {
+ return pass;
}
- public void setPassing(String passing) {
- this.passing = passing;
+ public void setPass(String pass) {
+ this.pass = pass;
}
- public String getFailing() {
- return failing;
+ public String getFail() {
+ return fail;
}
- public void setFailing(String failing) {
- this.failing = failing;
+ public void setFail(String fail) {
+ this.fail = fail;
}
}
diff --git a/plugins/org.eclipse.osee.disposition.rest/src/org/eclipse/osee/disposition/rest/DispoApi.java b/plugins/org.eclipse.osee.disposition.rest/src/org/eclipse/osee/disposition/rest/DispoApi.java
index f1095bcb89..e494bc8854 100644
--- a/plugins/org.eclipse.osee.disposition.rest/src/org/eclipse/osee/disposition/rest/DispoApi.java
+++ b/plugins/org.eclipse.osee.disposition.rest/src/org/eclipse/osee/disposition/rest/DispoApi.java
@@ -15,6 +15,7 @@ import java.util.HashMap;
import java.util.List;
import org.eclipse.osee.disposition.model.CiSetData;
import org.eclipse.osee.disposition.model.CopySetParams;
+import org.eclipse.osee.disposition.model.Discrepancy;
import org.eclipse.osee.disposition.model.DispoAnnotationData;
import org.eclipse.osee.disposition.model.DispoConfig;
import org.eclipse.osee.disposition.model.DispoItem;
@@ -57,6 +58,10 @@ public interface DispoApi {
String createDispoAnnotation(BranchId branch, String itemId, DispoAnnotationData annotation, String userName, boolean isCi);
+ String createDispoDiscrepancy(BranchId branch, String itemId, Discrepancy discrepancy, String userName);
+
+ boolean editDispoDiscrepancy(BranchId branch, String itemId, String discrepancyId, Discrepancy newDiscrepancy, String userName);
+
void editDispoSet(BranchId branch, String dispoSetId, DispoSetData newDispoSet);
boolean editDispoItem(BranchId branch, String itemId, DispoItemData newDispoItem);
@@ -79,6 +84,8 @@ public interface DispoApi {
boolean deleteAllDispoAnnotation(BranchId branch, String itemId, String userName, boolean isCi);
+ boolean deleteDispoDiscrepancy(BranchId branch, String itemId, String discrepancyId, String userName);
+
// Utilities
boolean isUniqueProgramName(String name);
diff --git a/plugins/org.eclipse.osee.disposition.rest/src/org/eclipse/osee/disposition/rest/internal/DispoApiImpl.java b/plugins/org.eclipse.osee.disposition.rest/src/org/eclipse/osee/disposition/rest/internal/DispoApiImpl.java
index a259e35a59..c1f54ac8c5 100644
--- a/plugins/org.eclipse.osee.disposition.rest/src/org/eclipse/osee/disposition/rest/internal/DispoApiImpl.java
+++ b/plugins/org.eclipse.osee.disposition.rest/src/org/eclipse/osee/disposition/rest/internal/DispoApiImpl.java
@@ -693,4 +693,88 @@ public class DispoApiImpl implements DispoApi {
return getQuery().getAllCiSets();
}
+ @Override
+ public String createDispoDiscrepancy(BranchId branch, String itemId, Discrepancy discrepancy, String userName) {
+ String idOfNewDiscrepancy = "";
+ DispoItem dispoItem = getQuery().findDispoItemById(branch, itemId);
+ if (dispoItem != null) {
+ Map<String, Discrepancy> discrepancyList = dispoItem.getDiscrepanciesList();
+
+ idOfNewDiscrepancy = dataFactory.getNewId();
+ discrepancy.setId(idOfNewDiscrepancy);
+ discrepancy.setLocation("");
+ discrepancy.setText("");
+
+ discrepancyList.put(idOfNewDiscrepancy, discrepancy);
+
+ DispoItemData newItem = new DispoItemData();
+ newItem.setDiscrepanciesList(discrepancyList);
+ newItem.setStatus(dispoConnector.getItemStatus(newItem));
+
+ ArtifactReadable author = getQuery().findUser();
+ DispoStorageMetadata metadata = new DispoStorageMetadata();
+ getWriter().updateDispoItem(author, branch, dispoItem.getGuid(), newItem, metadata);
+ if (!metadata.getIdsOfUpdatedItems().isEmpty()) {
+ updateBroadcaster.broadcastUpdateItems(metadata.getIdsOfUpdatedItems(), singleton(dispoItem),
+ getDispoItemParentSet(branch, itemId));
+ }
+ }
+ return idOfNewDiscrepancy;
+ }
+
+ @Override
+ public boolean editDispoDiscrepancy(BranchId branch, String itemId, String discrepancyId, Discrepancy newDiscrepancy, String userName) {
+ boolean wasUpdated = false;
+ DispoItem dispoItem = getQuery().findDispoItemById(branch, itemId);
+ if (dispoItem != null) {
+ Map<String, Discrepancy> discrepanciesList = dispoItem.getDiscrepanciesList();
+ discrepanciesList.put(discrepancyId, newDiscrepancy);
+
+ DispoItemData modifiedDispoItem = DispoUtil.itemArtToItemData(getDispoItemById(branch, itemId), true);
+ modifiedDispoItem.setDiscrepanciesList(discrepanciesList);
+ modifiedDispoItem.setStatus(dispoConnector.getItemStatus(modifiedDispoItem));
+
+ DispoStorageMetadata metadata = new DispoStorageMetadata();
+ try {
+ Date date = DispoUtil.getTimestampOfFile(getFullFilePathFromDispoItemId(branch, itemId, dispoItem));
+ modifiedDispoItem.setLastUpdate(date);
+ } catch (Throwable ex) {
+ throw new OseeCoreException(ex);
+ }
+
+ ArtifactReadable author = getQuery().findUser();
+ getWriter().updateDispoItem(author, branch, dispoItem.getGuid(), modifiedDispoItem, metadata);
+ if (!metadata.getIdsOfUpdatedItems().isEmpty()) {
+ updateBroadcaster.broadcastUpdateItems(metadata.getIdsOfUpdatedItems(), singleton(modifiedDispoItem),
+ getDispoItemParentSet(branch, itemId));
+ }
+ wasUpdated = true;
+ }
+ return wasUpdated;
+ }
+
+ @Override
+ public boolean deleteDispoDiscrepancy(BranchId branch, String itemId, String discrepancyId, String userName) {
+ boolean wasUpdated = false;
+ DispoItem dispoItem = getQuery().findDispoItemById(branch, itemId);
+ if (dispoItem != null) {
+ Map<String, Discrepancy> discrepanciesList = dispoItem.getDiscrepanciesList();
+ discrepanciesList.remove(discrepancyId);
+
+ DispoItemData newItem = new DispoItemData();
+ newItem.setDiscrepanciesList(discrepanciesList);
+ newItem.setStatus(dispoConnector.getItemStatus(newItem));
+
+ ArtifactReadable author = getQuery().findUser();
+ DispoStorageMetadata metadata = new DispoStorageMetadata();
+ getWriter().updateDispoItem(author, branch, dispoItem.getGuid(), newItem, metadata);
+ if (!metadata.getIdsOfUpdatedItems().isEmpty()) {
+ updateBroadcaster.broadcastUpdateItems(metadata.getIdsOfUpdatedItems(), singleton(newItem),
+ getDispoItemParentSet(branch, itemId));
+ }
+ wasUpdated = true;
+ }
+ return wasUpdated;
+ }
+
}
diff --git a/plugins/org.eclipse.osee.disposition.rest/src/org/eclipse/osee/disposition/rest/internal/DispoConnector.java b/plugins/org.eclipse.osee.disposition.rest/src/org/eclipse/osee/disposition/rest/internal/DispoConnector.java
index f6fa1bde04..0091a0258c 100644
--- a/plugins/org.eclipse.osee.disposition.rest/src/org/eclipse/osee/disposition/rest/internal/DispoConnector.java
+++ b/plugins/org.eclipse.osee.disposition.rest/src/org/eclipse/osee/disposition/rest/internal/DispoConnector.java
@@ -78,12 +78,13 @@ public class DispoConnector {
}
private boolean allAnnotationsValid(List<DispoAnnotationData> annotations) {
- for (DispoAnnotationData annotation : annotations) {
- if (!annotation.getIsDefault() && !annotation.isValid()) {
- return false;
+ if (annotations != null) {
+ for (DispoAnnotationData annotation : annotations) {
+ if (!annotation.getIsDefault() && !annotation.isValid()) {
+ return false;
+ }
}
}
-
return true;
}
@@ -99,16 +100,17 @@ public class DispoConnector {
private HashSet<String> getAllCoveredDiscrepanciesFromAnnotations(Map<String, Discrepancy> discrepancies, List<DispoAnnotationData> annotations) {
HashSet<String> toReturn = new HashSet<>();
- for (DispoAnnotationData annotation : annotations) {
- List<String> idsOfCoveredDiscrepancies = annotation.getIdsOfCoveredDiscrepancies();
- for (String id : idsOfCoveredDiscrepancies) {
- if (discrepancies.containsKey(id)) {
- Discrepancy discrepancy = discrepancies.get(id);
- toReturn.add(discrepancy.getLocation());
+ if (annotations != null) {
+ for (DispoAnnotationData annotation : annotations) {
+ List<String> idsOfCoveredDiscrepancies = annotation.getIdsOfCoveredDiscrepancies();
+ for (String id : idsOfCoveredDiscrepancies) {
+ if (discrepancies.containsKey(id)) {
+ Discrepancy discrepancy = discrepancies.get(id);
+ toReturn.add(discrepancy.getLocation());
+ }
}
}
}
-
return toReturn;
}
diff --git a/plugins/org.eclipse.osee.disposition.rest/src/org/eclipse/osee/disposition/rest/resources/ContinuousIntegrationResource.java b/plugins/org.eclipse.osee.disposition.rest/src/org/eclipse/osee/disposition/rest/resources/ContinuousIntegrationResource.java
index ac7d74cdc0..9f643b74a6 100644
--- a/plugins/org.eclipse.osee.disposition.rest/src/org/eclipse/osee/disposition/rest/resources/ContinuousIntegrationResource.java
+++ b/plugins/org.eclipse.osee.disposition.rest/src/org/eclipse/osee/disposition/rest/resources/ContinuousIntegrationResource.java
@@ -23,9 +23,13 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.eclipse.osee.disposition.model.CiItemData;
import org.eclipse.osee.disposition.model.CiSetData;
+import org.eclipse.osee.disposition.model.CiTestPoint;
+import org.eclipse.osee.disposition.model.Discrepancy;
import org.eclipse.osee.disposition.model.DispoAnnotationData;
import org.eclipse.osee.disposition.model.DispoItem;
+import org.eclipse.osee.disposition.model.DispoItemData;
import org.eclipse.osee.disposition.rest.DispoApi;
+import org.eclipse.osee.disposition.rest.util.DispoUtil;
import org.eclipse.osee.framework.core.data.BranchId;
/**
@@ -86,6 +90,7 @@ public class ContinuousIntegrationResource {
BranchId branch = BranchId.valueOf(data.getSetData().getBranchId());
String itemId = dispoApi.getDispoItemId(branch, data.getSetData().getDispoSetId(), data.getScriptName());
if (itemId != null && !itemId.isEmpty()) {
+ updateDiscrepencies(data, branch, itemId, userName);
dispoApi.deleteAllDispoAnnotation(branch, itemId, userName, true);
response = createAndUpdateAnnotation(data, userName, response, branch, itemId);
}
@@ -95,6 +100,30 @@ public class ContinuousIntegrationResource {
return response;
}
+ private void updateDiscrepencies(CiItemData data, BranchId branch, String itemId, String userName) {
+ CiTestPoint testPoints = data.getTestPoints();
+ DispoItem item = dispoApi.getDispoItemById(branch, itemId);
+ DispoItemData itemData = DispoUtil.itemArtToItemData(item, true);
+ String asRanges = itemData.getDiscrepanciesAsRanges();
+ if (!testPoints.getFail().equals(asRanges)) {
+ // remove ones that are now passing
+ List<Integer> ranges = DispoUtil.splitDiscrepancyLocations(testPoints.getPass());
+ List<String> discrepToRemove = DispoUtil.findDiscrepancyLocsToRemove(ranges, item);
+ for (String toRemove : discrepToRemove) {
+ dispoApi.deleteDispoDiscrepancy(branch, itemId, toRemove, userName);
+ }
+ // add ones that are new
+ ranges = DispoUtil.splitDiscrepancyLocations(testPoints.getFail());
+ List<String> discrepToAdd = DispoUtil.findMissingDiscrepancyLocs(ranges, item);
+ for (String toAdd : discrepToAdd) {
+ Discrepancy discrepancy = new Discrepancy();
+ String discrepancyId = dispoApi.createDispoDiscrepancy(branch, itemId, discrepancy, userName);
+ discrepancy.setLocation(toAdd);
+ dispoApi.editDispoDiscrepancy(branch, itemId, discrepancyId, discrepancy, userName);
+ }
+ }
+ }
+
private Response createAndUpdateAnnotation(CiItemData data, String userName, Response response, BranchId branchId, String itemId) {
for (DispoAnnotationData annotation : data.getAnnotations()) {
DispoAnnotationData temp = new DispoAnnotationData();
diff --git a/plugins/org.eclipse.osee.disposition.rest/src/org/eclipse/osee/disposition/rest/util/DispoUtil.java b/plugins/org.eclipse.osee.disposition.rest/src/org/eclipse/osee/disposition/rest/util/DispoUtil.java
index 5aa7431a98..fa8d987ff8 100644
--- a/plugins/org.eclipse.osee.disposition.rest/src/org/eclipse/osee/disposition/rest/util/DispoUtil.java
+++ b/plugins/org.eclipse.osee.disposition.rest/src/org/eclipse/osee/disposition/rest/util/DispoUtil.java
@@ -17,8 +17,11 @@ import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
import org.eclipse.osee.disposition.model.Discrepancy;
import org.eclipse.osee.disposition.model.DispoAnnotationData;
import org.eclipse.osee.disposition.model.DispoConfig;
@@ -567,4 +570,57 @@ public final class DispoUtil {
return null;
}
+ public static List<Integer> splitDiscrepancyLocations(String locations) {
+ String[] locationString = locations.split(",");
+ List<Integer> range = new ArrayList<>();
+ if (locations != null && !locations.isEmpty()) {
+ for (String location : locationString) {
+ String[] loc = location.split("-");
+ if (loc.length > 1) {
+ range.addAll(
+ IntStream.range(Integer.valueOf(loc[0].trim()), Integer.valueOf(loc[1].trim()) + 1).boxed().collect(
+ Collectors.toList()));
+ } else {
+ range.add(Integer.valueOf(loc[0].trim()));
+ }
+ }
+ }
+ return range;
+ }
+
+ public static List<String> findDiscrepancyLocsToRemove(List<Integer> ranges, DispoItem item) {
+ List<String> removeDiscrepancies = new ArrayList<>();
+ if (ranges != null && !ranges.isEmpty()) {
+ for (Integer locRef : ranges) {
+ for (Entry<String, Discrepancy> discrepancy : item.getDiscrepanciesList().entrySet()) {
+ Discrepancy value = discrepancy.getValue();
+ if (locRef == Integer.valueOf(value.getLocation())) {
+ removeDiscrepancies.add(discrepancy.getKey());
+ }
+ }
+ }
+ }
+ return removeDiscrepancies;
+ }
+
+ public static List<String> findMissingDiscrepancyLocs(List<Integer> ranges, DispoItem item) {
+ List<String> missingDiscrepanciesLoc = new ArrayList<>();
+ if (ranges != null && !ranges.isEmpty()) {
+ for (Integer locRef : ranges) {
+ boolean found = false;
+ for (Entry<String, Discrepancy> discrepancy : item.getDiscrepanciesList().entrySet()) {
+ Discrepancy value = discrepancy.getValue();
+ if (locRef == Integer.valueOf(value.getLocation())) {
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ missingDiscrepanciesLoc.add(String.valueOf(locRef));
+ }
+ }
+ }
+ return missingDiscrepanciesLoc;
+ }
+
}

Back to the top