From b0355c8bce9cc4bc3afc8af6843428d4b658ac6b Mon Sep 17 00:00:00 2001 From: donald.g.dunne Date: Wed, 24 Aug 2016 09:24:07 -0700 Subject: feature[ats_ATS311437]: Add ORCS Writer update for relations Change-Id: I8ad3b99401d07b6acb7f7c01473cf59bba93a9a8 --- .../tests/ats/resource/OrcsWriterEndpointTest.java | 8 + .../osee/orcs/rest/model/OrcsWriterEndpoint.java | 1 + .../orcs/rest/model/writer/OrcsWriterResponse.java | 37 +++++ .../OSEE-INF/web/writer/orcsWriter.js | 78 ++++----- .../internal/writer/OrcsCollectorValidator.java | 52 ++++-- .../rest/internal/writer/OrcsCollectorWriter.java | 185 ++++++++++++--------- .../internal/writer/OrcsWriterEndpointImpl.java | 148 +++++++++++++---- .../internal/writer/OrcsWriterExcelReader.java | 19 ++- .../OrcsWriterSheetProcessorForCreateUpdate.java | 24 +-- .../writer/OrcsWriterSheetProcessorForDelete.java | 2 +- .../OrcsWriterSheetProcessorForSettings.java | 3 +- .../orcs/rest/internal/writer/OrcsWriterUtil.java | 8 +- .../writer/OrcsWriterWorkbookGenerator.java | 2 - .../osee/orcs/rest/internal/writer/OwFactory.java | 3 +- 14 files changed, 377 insertions(+), 193 deletions(-) create mode 100644 plugins/org.eclipse.osee.orcs.rest.model/src/org/eclipse/osee/orcs/rest/model/writer/OrcsWriterResponse.java diff --git a/plugins/org.eclipse.osee.ats.client.integration.tests/src/org/eclipse/osee/ats/client/integration/tests/ats/resource/OrcsWriterEndpointTest.java b/plugins/org.eclipse.osee.ats.client.integration.tests/src/org/eclipse/osee/ats/client/integration/tests/ats/resource/OrcsWriterEndpointTest.java index 00a9bcdb088..bf16b1dab13 100644 --- a/plugins/org.eclipse.osee.ats.client.integration.tests/src/org/eclipse/osee/ats/client/integration/tests/ats/resource/OrcsWriterEndpointTest.java +++ b/plugins/org.eclipse.osee.ats.client.integration.tests/src/org/eclipse/osee/ats/client/integration/tests/ats/resource/OrcsWriterEndpointTest.java @@ -17,6 +17,7 @@ import java.util.Collections; import java.util.List; import javax.ws.rs.core.Response; import org.eclipse.osee.ats.client.integration.tests.AtsClientService; +import org.eclipse.osee.ats.demo.api.DemoUsers; import org.eclipse.osee.framework.core.enums.CoreArtifactTypes; import org.eclipse.osee.framework.core.enums.CoreAttributeTypes; import org.eclipse.osee.framework.core.enums.CoreBranches; @@ -69,6 +70,8 @@ public class OrcsWriterEndpointTest extends AbstractRestTest { @Test public void testValidate() throws Exception { OwCollector collector = getDefaultOwCollector(); + collector.setAsUserId(DemoUsers.Joe_Smith.getUserId()); + collector.setPersistComment(getClass().getSimpleName() + " - testValidate"); Response response = writer.getOrcsWriterValidate(collector); assertEquals(javax.ws.rs.core.Response.Status.OK.getStatusCode(), response.getStatus()); } @@ -76,6 +79,8 @@ public class OrcsWriterEndpointTest extends AbstractRestTest { @Test public void testPersist() throws Exception { OwCollector collector = getDefaultOwCollector(); + collector.setAsUserId(DemoUsers.Joe_Smith.getUserId()); + collector.setPersistComment(getClass().getSimpleName() + " - testPersist"); Response response = writer.getOrcsWriterPersist(collector); assertEquals(javax.ws.rs.core.Response.Status.OK.getStatusCode(), response.getStatus()); @@ -122,6 +127,9 @@ public class OrcsWriterEndpointTest extends AbstractRestTest { owToken.setData(tokenStr); collector.getDelete().add(owToken); + collector.setAsUserId(DemoUsers.Joe_Smith.getUserId()); + collector.setPersistComment(getClass().getSimpleName() + " - testValidate"); + Response response = writer.getOrcsWriterPersist(collector); assertEquals(javax.ws.rs.core.Response.Status.OK.getStatusCode(), response.getStatus()); diff --git a/plugins/org.eclipse.osee.orcs.rest.model/src/org/eclipse/osee/orcs/rest/model/OrcsWriterEndpoint.java b/plugins/org.eclipse.osee.orcs.rest.model/src/org/eclipse/osee/orcs/rest/model/OrcsWriterEndpoint.java index a64b8470939..09494a7a87d 100644 --- a/plugins/org.eclipse.osee.orcs.rest.model/src/org/eclipse/osee/orcs/rest/model/OrcsWriterEndpoint.java +++ b/plugins/org.eclipse.osee.orcs.rest.model/src/org/eclipse/osee/orcs/rest/model/OrcsWriterEndpoint.java @@ -61,6 +61,7 @@ public interface OrcsWriterEndpoint { @POST @Path("writer") @Consumes({MediaType.APPLICATION_JSON}) + @Produces({MediaType.APPLICATION_JSON}) Response getOrcsWriterPersist(OwCollector collector); @POST diff --git a/plugins/org.eclipse.osee.orcs.rest.model/src/org/eclipse/osee/orcs/rest/model/writer/OrcsWriterResponse.java b/plugins/org.eclipse.osee.orcs.rest.model/src/org/eclipse/osee/orcs/rest/model/writer/OrcsWriterResponse.java new file mode 100644 index 00000000000..dbf3090f52b --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.rest.model/src/org/eclipse/osee/orcs/rest/model/writer/OrcsWriterResponse.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (c) 2016 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.orcs.rest.model.writer; + +/** + * @author Donald G. Dunne + */ +public class OrcsWriterResponse { + + private String message; + private String title; + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + +} diff --git a/plugins/org.eclipse.osee.orcs.rest/OSEE-INF/web/writer/orcsWriter.js b/plugins/org.eclipse.osee.orcs.rest/OSEE-INF/web/writer/orcsWriter.js index 086102b71c1..1816d4ff3d7 100644 --- a/plugins/org.eclipse.osee.orcs.rest/OSEE-INF/web/writer/orcsWriter.js +++ b/plugins/org.eclipse.osee.orcs.rest/OSEE-INF/web/writer/orcsWriter.js @@ -45,29 +45,17 @@ app 'Accept' : 'application/json', 'Content-Type' : 'application/json' } - }) - .success( - function(data, status, - headers, config) { - $scope.message += "\nValidation Passed"; - if (!validate) { - $scope.message += "...Execution Succeeded"; - } - }) - .error( - function(data, status, - headers, config) { - var message = 'error - status: ' - + status - + ' ' - + data; - if (data.exception) { - message += ' Exception: ' - + data.exception; - } - $scope.message += '\n' - + message; - }); + }).success( + function(data, status, headers, + config) { + $scope.message += '\n\n' + + data.message; + }).error( + function(data, status, headers, + config) { + $scope.message += '\n\n' + + data.message; + }); } else if ($scope.file) { $scope.message = "Processing EXCEL XML"; $suffix = ".xml"; @@ -76,33 +64,23 @@ app - $suffix.length) == -1) { $scope.message += "\n\nError: File must be Excel XML 2003 format with .xml extension."; } else { - Upload - .upload({ - url : url + '/excel', - file : $scope.file - }) - .success( - function(data, status, - headers, config) { - $scope.message += "\nValidation Passed"; - if (!validate) { - $scope.message += "...Execution Succeeded"; - } - }) - .error( - function(data, status, - headers, config) { - var message = 'error - status: ' - + status - + ' ' - + data; - if (data.exception) { - message += ' Exception: ' - + data.exception; - } - $scope.message += '\n' - + message; - }); + Upload.upload({ + url : url + '/excel', + file : $scope.file + }).success( + function(data, status, headers, + config) { + $scope.message += '\n\n' + + data.message; + }).error( + function(data, status, headers, + config) { + var errStr = data.message; + if (typeof errStr == 'undefined') { + errStr = data; + } + $scope.message += '\n\n' + errStr; + }); } } } diff --git a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/writer/OrcsCollectorValidator.java b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/writer/OrcsCollectorValidator.java index b2d02db7777..011946354df 100644 --- a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/writer/OrcsCollectorValidator.java +++ b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/writer/OrcsCollectorValidator.java @@ -14,6 +14,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; +import org.eclipse.osee.framework.core.enums.SystemUser; import org.eclipse.osee.framework.core.util.XResultData; import org.eclipse.osee.framework.jdk.core.util.Strings; import org.eclipse.osee.orcs.OrcsApi; @@ -53,9 +54,14 @@ public class OrcsCollectorValidator { branchValid = validateBranch(results); if (!helper.isUserExists(collector.getAsUserId())) { results.errorf("Invalid asUserId [%s].\n", collector.getAsUserId()); + } else if (collector.getAsUserId().equals(SystemUser.OseeSystem.getUserId())) { + results.errorf("Invalid AS USER ID [%s]. Enter userId of user making change.\n", collector.getAsUserId()); } if (!Strings.isValid(collector.getPersistComment())) { results.errorf("Invalid persistComment [%s].\n", collector.getPersistComment()); + } else if (collector.getPersistComment().toLowerCase().contains("enter persist comment")) { + results.errorf("Invalid persistComment [%s]. Enter why change is being made.\n", + collector.getPersistComment()); } boolean createEntries = collector.getCreate() != null && !collector.getCreate().isEmpty(); boolean updateEntries = collector.getUpdate() != null && !collector.getUpdate().isEmpty(); @@ -64,6 +70,8 @@ public class OrcsCollectorValidator { results.error("No create, update or delete entries.\n"); } validateCreate(results); + validateUpdate(results); + results.log("Completed"); return results; } @@ -71,8 +79,16 @@ public class OrcsCollectorValidator { for (OwArtifact artifact : collector.getCreate()) { validateArtifactType(results, artifact); validateArtifactDoesNotExist(results, artifact); - validateCreateAttributes(artifact, results); - validateCreateRelations(artifact, results); + validateCreateUpdateAttributes(artifact, results); + validateCreateUpdateRelations(artifact, results); + } + } + + private void validateUpdate(XResultData results) { + for (OwArtifact artifact : collector.getUpdate()) { + validateArtifactDoesExist(results, artifact); + validateCreateUpdateAttributes(artifact, results); + validateCreateUpdateRelations(artifact, results); } } @@ -102,7 +118,23 @@ public class OrcsCollectorValidator { } } - private void validateCreateRelations(OwArtifact artifact, XResultData results) { + private void validateArtifactDoesExist(XResultData results, OwArtifact artifact) { + long artifactUuid = artifact.getUuid(); + if (!branchValid) { + results.errorf("Invalid Branch; can't validate artifact uuid for [%s].\n", artifact); + } else if (artifactUuid > 0L) { + if (!helper.isArtifactExists(collector.getBranch().getUuid(), artifactUuid)) { + results.errorf("Artifact with uuid does not exist [%s].\n", artifact); + } else { + if (uuidToArtifact == null) { + uuidToArtifact = new HashMap<>(); + } + uuidToArtifact.put(artifactUuid, artifact); + } + } + } + + private void validateCreateUpdateRelations(OwArtifact artifact, XResultData results) { for (OwRelation relation : artifact.getRelations()) { if (!branchValid) { results.errorf("Invalid Branch; can't validate artifact uuid for artifact [%s] and relation [%s].\n", @@ -142,7 +174,7 @@ public class OrcsCollectorValidator { } } - private void validateCreateAttributes(OwArtifact artifact, XResultData results) { + private void validateCreateUpdateAttributes(OwArtifact artifact, XResultData results) { String name = artifact.getName(); if (!Strings.isValid(name)) { results.errorf("Artifact [%s] does not have Name attribute.\n", artifact); @@ -152,14 +184,10 @@ public class OrcsCollectorValidator { if (attrType == null) { results.errorf("Invalid Attribute Type for artifact [%s].\n", artifact); - } else if (attrType.getUuid() <= 0L) { - if (!helper.isAttributeTypeExists(attrType.getName())) { - results.errorf("Invalid Attribute Type uuid [%s] for artifact [%s].\n", attrType, artifact); - } - } else { - if (!helper.isAttributeTypeExists(attrType.getUuid())) { - results.errorf("Attribute Type [%s] does not exist for artifact [%s].\n", attrType, artifact); - } + } else if (attrType.getUuid() <= 0L && !helper.isAttributeTypeExists(attrType.getName())) { + results.errorf("Invalid Attribute Type uuid [%s] for artifact [%s].\n", attrType, artifact); + } else if (attrType.getUuid() > 0L && !helper.isAttributeTypeExists(attrType.getUuid())) { + results.errorf("Attribute Type [%s] does not exist for artifact [%s].\n", attrType, artifact); } } } diff --git a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/writer/OrcsCollectorWriter.java b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/writer/OrcsCollectorWriter.java index 07937a669e1..ebccad67cdb 100644 --- a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/writer/OrcsCollectorWriter.java +++ b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/writer/OrcsCollectorWriter.java @@ -21,8 +21,12 @@ import org.eclipse.osee.framework.core.data.BranchId; import org.eclipse.osee.framework.core.data.IArtifactType; import org.eclipse.osee.framework.core.data.IAttributeType; import org.eclipse.osee.framework.core.data.IRelationType; +import org.eclipse.osee.framework.core.data.IRelationTypeSide; +import org.eclipse.osee.framework.core.data.TokenFactory; import org.eclipse.osee.framework.core.enums.CoreAttributeTypes; import org.eclipse.osee.framework.core.enums.CoreBranches; +import org.eclipse.osee.framework.core.enums.RelationSide; +import org.eclipse.osee.framework.core.exception.OseeWrappedException; import org.eclipse.osee.framework.core.util.XResultData; import org.eclipse.osee.framework.jdk.core.type.OseeArgumentException; import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; @@ -63,12 +67,11 @@ public class OrcsCollectorWriter { } public XResultData run() { - XResultData results = new XResultData(false); processCreate(results); processUpdate(results); processDelete(results); - getTransaction().commit(); + results.log("Complete"); return results; } @@ -99,92 +102,104 @@ public class OrcsCollectorWriter { logChange(artifact, CoreAttributeTypes.Name, artifact.getName(), owArtifact.getName()); } - for (OwAttribute owAttribute : owArtifact.getAttributes()) { - IAttributeType attrType = getAttributeType(owAttribute.getType()); + try { + createMissingRelations(owArtifact.getRelations(), artifact, results); + } catch (Exception ex) { + throw new OseeWrappedException(ex, "Exception processing relations for [%s]", owArtifact); + } - if (artifact.getAttributeCount(attrType) <= 1 && owAttribute.getValues().size() <= 1) { - String currValue = artifact.getSoleAttributeAsString(attrType, null); + try { + for (OwAttribute owAttribute : owArtifact.getAttributes()) { + IAttributeType attrType = getAttributeType(owAttribute.getType()); - String newValue = null; - if (owAttribute.getValues().size() == 1) { - Object object = owAttribute.getValues().iterator().next(); - if (object != null) { - newValue = owAttribute.getValues().iterator().next().toString(); + if (artifact.getAttributeCount(attrType) <= 1 && owAttribute.getValues().size() <= 1) { + String currValue = artifact.getSoleAttributeAsString(attrType, null); + + String newValue = null; + if (owAttribute.getValues().size() == 1) { + Object object = owAttribute.getValues().iterator().next(); + if (object != null) { + newValue = owAttribute.getValues().iterator().next().toString(); + } } - } - // handle delete attribute case first - if (Strings.isValid(currValue) && newValue == null) { - logChange(artifact, attrType, currValue, newValue); - getTransaction().deleteAttributes(artifact, attrType); - } else if (orcsApi.getOrcsTypes().getAttributeTypes().isBooleanType(attrType)) { - Boolean currVal = getBoolean(currValue); - Boolean newVal = getBoolean(newValue); - if (currVal == null || !currVal.equals(newVal)) { + // handle delete attribute case first + if (Strings.isValid(currValue) && newValue == null) { logChange(artifact, attrType, currValue, newValue); - getTransaction().setSoleAttributeValue(artifact, attrType, newVal); - } - } else if (orcsApi.getOrcsTypes().getAttributeTypes().isFloatingType(attrType)) { - try { - Double currVal = getDouble(currValue); - Double newVal = getDouble(newValue); + getTransaction().deleteAttributes(artifact, attrType); + } else if (orcsApi.getOrcsTypes().getAttributeTypes().isBooleanType(attrType)) { + Boolean currVal = getBoolean(currValue); + Boolean newVal = getBoolean(newValue); if (currVal == null || !currVal.equals(newVal)) { logChange(artifact, attrType, currValue, newValue); getTransaction().setSoleAttributeValue(artifact, attrType, newVal); } - } catch (Exception ex) { - throw new OseeArgumentException("Exception processing Double for OwAttribute %s Exception %s", - owAttribute, ex); - } - } else if (orcsApi.getOrcsTypes().getAttributeTypes().isIntegerType(attrType)) { - try { - Integer currVal = getInteger(currValue); - Integer newVal = getInteger(newValue); - if (currVal == null || !currVal.equals(newVal)) { - logChange(artifact, attrType, currValue, newValue); - getTransaction().setSoleAttributeValue(artifact, attrType, newVal); + } else if (orcsApi.getOrcsTypes().getAttributeTypes().isFloatingType(attrType)) { + try { + Double currVal = getDouble(currValue); + Double newVal = getDouble(newValue); + if (currVal == null || !currVal.equals(newVal)) { + logChange(artifact, attrType, currValue, newValue); + getTransaction().setSoleAttributeValue(artifact, attrType, newVal); + } + } catch (Exception ex) { + throw new OseeArgumentException("Exception processing Double for OwAttribute %s Exception %s", + owAttribute, ex); } - } catch (Exception ex) { - throw new OseeArgumentException("Exception processing Integer for OwAttribute %s Exception %s", - owAttribute, ex); - } - } else if (orcsApi.getOrcsTypes().getAttributeTypes().isDateType(attrType)) { - try { - Date currVal = artifact.getSoleAttributeValue(attrType, null); - Date newVal = getDate(newValue); - if (currVal == null || currVal.compareTo(newVal) != 0) { - logChange(artifact, attrType, DateUtil.getMMDDYYHHMM(currVal), DateUtil.getMMDDYYHHMM(newVal)); - TransactionBuilder tx = getTransaction(); - tx.setSoleAttributeValue(artifact, attrType, newVal); + } else if (orcsApi.getOrcsTypes().getAttributeTypes().isIntegerType(attrType)) { + try { + Integer currVal = getInteger(currValue); + Integer newVal = getInteger(newValue); + if (currVal == null || !currVal.equals(newVal)) { + logChange(artifact, attrType, currValue, newValue); + getTransaction().setSoleAttributeValue(artifact, attrType, newVal); + } + } catch (Exception ex) { + throw new OseeArgumentException("Exception processing Integer for OwAttribute %s Exception %s", + owAttribute, ex); + } + } else if (orcsApi.getOrcsTypes().getAttributeTypes().isDateType(attrType)) { + try { + Date currVal = artifact.getSoleAttributeValue(attrType, null); + Date newVal = getDate(newValue); + if (currVal == null || currVal.compareTo(newVal) != 0) { + logChange(artifact, attrType, DateUtil.getMMDDYYHHMM(currVal), + DateUtil.getMMDDYYHHMM(newVal)); + TransactionBuilder tx = getTransaction(); + tx.setSoleAttributeValue(artifact, attrType, newVal); + } + } catch (Exception ex) { + throw new OseeArgumentException("Exception processing Integer for OwAttribute %s Exception %s", + owAttribute, ex); } - } catch (Exception ex) { - throw new OseeArgumentException("Exception processing Integer for OwAttribute %s Exception %s", - owAttribute, ex); + } else if (currValue == null && newValue != null || currValue != null && !currValue.equals( + newValue)) { + logChange(artifact, attrType, currValue, newValue); + getTransaction().setSoleAttributeValue(artifact, attrType, newValue); } - } else if (currValue == null && newValue != null || currValue != null && !currValue.equals(newValue)) { - logChange(artifact, attrType, currValue, newValue); - getTransaction().setSoleAttributeValue(artifact, attrType, newValue); - } - } else if (owAttribute.getValues().size() > 1 && orcsApi.getOrcsTypes().getAttributeTypes().getMaxOccurrences( - attrType) > 1) { - if (orcsApi.getOrcsTypes().getAttributeTypes().isDateType(attrType)) { - throw new OseeArgumentException( - "Date attributes not supported for multi-value set for OwAttribute %s Exception %s", owAttribute); - } - List values = new LinkedList<>(); - for (Object obj : owAttribute.getValues()) { - values.add(obj.toString()); + } else if (owAttribute.getValues().size() > 1 && orcsApi.getOrcsTypes().getAttributeTypes().getMaxOccurrences( + attrType) > 1) { + if (orcsApi.getOrcsTypes().getAttributeTypes().isDateType(attrType)) { + throw new OseeArgumentException( + "Date attributes not supported for multi-value set for OwAttribute %s Exception %s", + owAttribute); + } + List values = new LinkedList<>(); + for (Object obj : owAttribute.getValues()) { + values.add(obj.toString()); + } + getTransaction().setAttributesFromStrings(artifact, attrType, values); + logChange(artifact, attrType, artifact.getAttributeValues(attrType).toString(), values.toString()); } - getTransaction().setAttributesFromStrings(artifact, attrType, values); - logChange(artifact, attrType, artifact.getAttributeValues(attrType).toString(), values.toString()); } - + } catch (Exception ex) { + throw new OseeWrappedException(ex, "Exception processing attributes for [%s]", owArtifact); } } } private void logChange(ArtifactReadable artifact, IAttributeType attrType, String currValue, String newValue) { - results.log(String.format("Attr Values not same; Current [%s], New [%s] for attr type [%s] and artifact %s", + results.log(String.format("Attribute Updated: Current [%s], New [%s] for attr type [%s] and artifact %s", currValue, newValue, attrType, artifact.toStringWithId())); } @@ -249,14 +264,26 @@ public class OrcsCollectorWriter { uuidToArtifact.put(artifactUuid, artifact); - createAttributes(owArtifact, artifact, results); + try { + createAttributes(owArtifact, artifact, results); + } catch (Exception ex) { + throw new OseeWrappedException(ex, "Exception creating attributes for [%s]", owArtifact); + } - createRelations(owArtifact, artifact, results); + try { + createMissingRelations(owArtifact, artifact, results); + } catch (Exception ex) { + throw new OseeWrappedException(ex, "Exception creating relations for [%s]", owArtifact); + } } } - private void createRelations(OwArtifact owArtifact, ArtifactId artifact, XResultData results) { - for (OwRelation relation : owArtifact.getRelations()) { + private void createMissingRelations(OwArtifact owArtifact, ArtifactId artifact, XResultData results) { + createMissingRelations(owArtifact.getRelations(), artifact, results); + } + + private void createMissingRelations(List relations, ArtifactId artifact, XResultData results) { + for (OwRelation relation : relations) { OwRelationType owRelType = relation.getType(); IRelationType relType = orcsApi.getOrcsTypes().getRelationTypes().getByUuid(owRelType.getUuid()); @@ -272,9 +299,17 @@ public class OrcsCollectorWriter { uuidToArtifact.put(artToken.getUuid(), otherArtifact); } if (relation.getType().isSideA()) { - getTransaction().relate(otherArtifact, relType, artifact); + IRelationTypeSide relTypeSide = TokenFactory.createRelationTypeSide(RelationSide.SIDE_A, + relation.getType().getUuid(), relation.getType().getName()); + if (!otherArtifact.areRelated(relTypeSide, (ArtifactReadable) artifact)) { + getTransaction().relate(otherArtifact, relType, artifact); + } } else { - getTransaction().relate(artifact, relType, otherArtifact); + IRelationTypeSide relTypeSide = TokenFactory.createRelationTypeSide(RelationSide.SIDE_B, + relation.getType().getUuid(), relation.getType().getName()); + if (!otherArtifact.areRelated(relTypeSide, (ArtifactReadable) artifact)) { + getTransaction().relate(artifact, relType, otherArtifact); + } } } } diff --git a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/writer/OrcsWriterEndpointImpl.java b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/writer/OrcsWriterEndpointImpl.java index e1311251559..aa85068b9b7 100644 --- a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/writer/OrcsWriterEndpointImpl.java +++ b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/writer/OrcsWriterEndpointImpl.java @@ -15,11 +15,11 @@ import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.ResponseBuilder; import javax.ws.rs.core.StreamingOutput; import org.apache.cxf.jaxrs.ext.multipart.Attachment; -import org.eclipse.osee.framework.core.exception.OseeWrappedException; import org.eclipse.osee.framework.core.util.XResultData; -import org.eclipse.osee.framework.jdk.core.type.OseeArgumentException; +import org.eclipse.osee.framework.jdk.core.util.Lib; import org.eclipse.osee.orcs.OrcsApi; import org.eclipse.osee.orcs.rest.model.OrcsWriterEndpoint; +import org.eclipse.osee.orcs.rest.model.writer.OrcsWriterResponse; import org.eclipse.osee.orcs.rest.model.writer.config.OrcsWriterInputConfig; import org.eclipse.osee.orcs.rest.model.writer.reader.OwCollector; @@ -28,6 +28,12 @@ import org.eclipse.osee.orcs.rest.model.writer.reader.OwCollector; */ public class OrcsWriterEndpointImpl implements OrcsWriterEndpoint { + private static final String EXCEPTION_READING_INPUT_S = "Exception reading input\n\n%s"; + private static final String ERROR_READING_INPUT_S = "Exception reading input\n\n%s"; + private static final String ERROR_VALIDATING_INPUT_S = "Error validating input\n\n%s"; + private static final String EXCEPTION_VALIDATING_INPUT_S = "Exception validating input\n\n%s"; + private static final String EXCEPTION_WRITING_CHANGES_S = "Exception writing changes\n\n%s"; + private static final String ERROR_WRITING_CHANGES_S = "Error writing changes:\n\n%s"; private final OrcsApi orcsApi; public OrcsWriterEndpointImpl(OrcsApi orcsApi) { @@ -63,77 +69,159 @@ public class OrcsWriterEndpointImpl implements OrcsWriterEndpoint { @Override public Response getOrcsWriterValidate(OwCollector collector) { + // Setup + OrcsWriterResponse response = new OrcsWriterResponse(); + response.setTitle("JSON Validator"); + XResultData results = null; + + // Validate try { OrcsCollectorValidator validator = new OrcsCollectorValidator(orcsApi, collector); - XResultData results = validator.run(); - if (results.isErrors()) { - return Response.serverError().entity(results.toString()).build(); - } - return Response.ok(results.toString()).build(); + results = validator.run(); } catch (Exception ex) { - throw new OseeWrappedException(ex); + response.setMessage(String.format(EXCEPTION_VALIDATING_INPUT_S, Lib.exceptionToString(ex))); + return Response.serverError().entity(response).build(); + } + if (results.isErrors()) { + response.setMessage(String.format(ERROR_VALIDATING_INPUT_S, results.toString())); + return Response.serverError().entity(response).build(); } + + // Return Success + response.setMessage("Success"); + return Response.ok(response).build(); } @Override public Response getOrcsWriterPersist(OwCollector collector) { - OrcsCollectorValidator validator = new OrcsCollectorValidator(orcsApi, collector); - XResultData results = validator.run(); + // Setup + OrcsWriterResponse response = new OrcsWriterResponse(); + response.setTitle("JSON Executor"); + XResultData results = null; + + // Validate + try { + OrcsCollectorValidator validator = new OrcsCollectorValidator(orcsApi, collector); + results = validator.run(); + } catch (Exception ex) { + response.setMessage(String.format(EXCEPTION_VALIDATING_INPUT_S, Lib.exceptionToString(ex))); + return Response.serverError().entity(response).build(); + } if (results.isErrors()) { - throw new OseeArgumentException(results.toString()); + response.setMessage(String.format(ERROR_VALIDATING_INPUT_S, results.toString())); + return Response.serverError().entity(response).build(); + } + + // Write + try { + OrcsCollectorWriter writer = new OrcsCollectorWriter(orcsApi, collector, results); + writer.run(); + } catch (Exception ex) { + response.setMessage(String.format(EXCEPTION_WRITING_CHANGES_S, Lib.exceptionToString(ex))); + return Response.serverError().entity(response).build(); } - OrcsCollectorWriter writer = new OrcsCollectorWriter(orcsApi, collector, results); - writer.run(); if (results.isErrors()) { - return Response.notModified().entity(results.toString()).build(); + response.setMessage(String.format(ERROR_WRITING_CHANGES_S, results.toString())); + return Response.serverError().entity(response).build(); } - return Response.ok().entity(results.toString()).build(); + + // Return Success + response.setMessage("Success"); + return Response.ok().entity(response).build(); } @Override public Response validateExcelInput(Attachment attachment) { + // Setup InputStream stream = attachment.getObject(InputStream.class); - + OrcsWriterResponse response = new OrcsWriterResponse(); + response.setTitle("Excel Validation"); XResultData results = new XResultData(); + + // Read Input OrcsWriterExcelReader reader = new OrcsWriterExcelReader(results); try { reader.run(stream); } catch (Exception ex) { - throw new OseeWrappedException(ex); + response.setMessage(String.format(EXCEPTION_READING_INPUT_S, Lib.exceptionToString(ex))); + return Response.serverError().entity(response).build(); + } + if (results.isErrors()) { + response.setMessage(String.format(ERROR_READING_INPUT_S, results.toString())); + return Response.serverError().entity(response).build(); } OwCollector collector = reader.getCollector(); - OrcsCollectorValidator validator = new OrcsCollectorValidator(orcsApi, collector); - results = validator.run(); + + // Validate + try { + OrcsCollectorValidator validator = new OrcsCollectorValidator(orcsApi, collector); + results = validator.run(); + } catch (Exception ex) { + response.setMessage(String.format(EXCEPTION_VALIDATING_INPUT_S, Lib.exceptionToString(ex))); + return Response.serverError().entity(response).build(); + } if (results.isErrors()) { - throw new OseeArgumentException(results.toString()); + response.setMessage(String.format(ERROR_VALIDATING_INPUT_S, results.toString())); + return Response.serverError().entity(response).build(); } - return Response.ok().entity(results.toString()).build(); + + // Return Success + response.setMessage("Success"); + return Response.ok().entity(response).build(); } @Override public Response persistExcelInput(Attachment attachment) { + // Setup InputStream stream = attachment.getObject(InputStream.class); - XResultData results = new XResultData(); + OrcsWriterResponse response = new OrcsWriterResponse(); + response.setTitle("Excel Executor"); + + // Read Input OrcsWriterExcelReader reader = new OrcsWriterExcelReader(results); try { reader.run(stream); } catch (Exception ex) { - throw new OseeWrappedException(ex); + response.setMessage(String.format(EXCEPTION_READING_INPUT_S, Lib.exceptionToString(ex))); + return Response.serverError().entity(response).build(); + } + if (results.isErrors()) { + response.setMessage(String.format(ERROR_READING_INPUT_S, results.toString())); + return Response.serverError().entity(response).build(); } OwCollector collector = reader.getCollector(); - OrcsCollectorValidator validator = new OrcsCollectorValidator(orcsApi, collector); - results = validator.run(); + // Validate + try { + OrcsCollectorValidator validator = new OrcsCollectorValidator(orcsApi, collector); + results = validator.run(); + } catch (Exception ex) { + response.setMessage(String.format(EXCEPTION_VALIDATING_INPUT_S, Lib.exceptionToString(ex))); + return Response.serverError().entity(response).build(); + } if (results.isErrors()) { - throw new OseeArgumentException(results.toString()); + response.setMessage(String.format(ERROR_VALIDATING_INPUT_S, results.toString())); + return Response.serverError().entity(response).build(); + } + + // Write + try { + OrcsCollectorWriter writer = new OrcsCollectorWriter(orcsApi, collector, results); + writer.run(); + } catch (Exception ex) { + response.setMessage(String.format(EXCEPTION_WRITING_CHANGES_S, Lib.exceptionToString(ex))); + return Response.serverError().entity(response).build(); } - OrcsCollectorWriter writer = new OrcsCollectorWriter(orcsApi, collector, results); - writer.run(); if (results.isErrors()) { - return Response.notModified().entity(results.toString()).build(); + response.setMessage(String.format(ERROR_WRITING_CHANGES_S, results.toString())); + return Response.serverError().entity(response).build(); } - return Response.ok().entity(results.toString()).build(); + + // Return Success + results.log("Success"); + response.setMessage(results.toString()); + return Response.ok().entity(response).build(); } } diff --git a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/writer/OrcsWriterExcelReader.java b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/writer/OrcsWriterExcelReader.java index bb231a704e3..83a5ca1d5e4 100644 --- a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/writer/OrcsWriterExcelReader.java +++ b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/writer/OrcsWriterExcelReader.java @@ -63,6 +63,7 @@ public class OrcsWriterExcelReader { private final XResultData result; private OrcsWriterSheetProcessorForCreateUpdate updateSheet; private OrcsWriterSheetProcessorForDelete deleteSheet; + private boolean skipSheet = true; public ExcelRowProcessor(OwCollector collector, XResultData result) { this.collector = collector; @@ -76,20 +77,21 @@ public class OrcsWriterExcelReader { @Override public void foundStartOfWorksheet(String sheetName) throws OseeCoreException { - System.out.println("Processing Sheet " + sheetName); this.sheetName = sheetName; if (sheetName.equals(OrcsWriterUtil.CREATE_SHEET_NAME)) { createSheet = new OrcsWriterSheetProcessorForCreateUpdate(collector, result, true); - return; + skipSheet = false; } else if (sheetName.equals(OrcsWriterUtil.UPDATE_SHEET_NAME)) { updateSheet = new OrcsWriterSheetProcessorForCreateUpdate(collector, result, false); - return; + skipSheet = false; } else if (sheetName.equals(OrcsWriterUtil.INSTRUCTIONS_AND_SETTINGS_SHEET_NAME)) { settingsSheet = new OrcsWriterSheetProcessorForSettings(collector, result); - return; + skipSheet = false; } else if (sheetName.equals(OrcsWriterUtil.DELETE_SHEET_NAME)) { deleteSheet = new OrcsWriterSheetProcessorForDelete(collector, result); - return; + skipSheet = false; + } else { + skipSheet = true; } } @@ -105,6 +107,9 @@ public class OrcsWriterExcelReader { @Override public void processHeaderRow(String[] headerRow) { + if (skipSheet) { + return; + } if (isCreateSheet()) { createSheet.processHeaderRow(headerRow); } else if (isUpdateSheet()) { @@ -132,6 +137,9 @@ public class OrcsWriterExcelReader { @Override public void processRow(String[] row) throws OseeCoreException { + if (skipSheet) { + return; + } if (isCreateSheet()) { processCreateSheetRow(row); } else if (isUpdateSheet()) { @@ -157,6 +165,7 @@ public class OrcsWriterExcelReader { @Override public void reachedEndOfWorksheet() { + skipSheet = true; // do nothing } diff --git a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/writer/OrcsWriterSheetProcessorForCreateUpdate.java b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/writer/OrcsWriterSheetProcessorForCreateUpdate.java index 60111b50593..67784faa72a 100644 --- a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/writer/OrcsWriterSheetProcessorForCreateUpdate.java +++ b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/writer/OrcsWriterSheetProcessorForCreateUpdate.java @@ -88,12 +88,12 @@ public class OrcsWriterSheetProcessorForCreateUpdate implements RowProcessor { nameColumn = colCount; } else if (value.toLowerCase().equals("attribute")) { OwAttributeType attrType = new OwAttributeType(); - attrType.setData("Column " + colCount); + attrType.setData(OrcsWriterUtil.getData(getSheetName(), rowCount, colCount, "")); columnToAttributeType.put(colCount, attrType); collector.getAttrTypes().add(attrType); } else if (value.toLowerCase().equals("relation")) { OwRelationType relType = new OwRelationType(); - relType.setData("Column " + colCount); + relType.setData(OrcsWriterUtil.getData(getSheetName(), rowCount, colCount, "")); columnToRelationType.put(colCount, relType); collector.getRelTypes().add(relType); } else if (value.toLowerCase().startsWith("new art token")) { @@ -121,14 +121,14 @@ public class OrcsWriterSheetProcessorForCreateUpdate implements RowProcessor { } private String getSheetName() { - return createSheet ? "CREATE" : "UPDATE"; + return createSheet ? OrcsWriterUtil.CREATE_SHEET_NAME : OrcsWriterUtil.UPDATE_SHEET_NAME; } @Override public void processRow(String[] row) throws OseeCoreException { rowCount++; OwArtifact artifact = new OwArtifact(); - artifact.setData("Row " + rowCount); + artifact.setData(OrcsWriterUtil.getData(getSheetName(), rowCount, 0, "")); if (rowCount == 2) { for (int colCount = 0; colCount < row.length; colCount++) { if (isAttributeColumn(colCount)) { @@ -188,8 +188,8 @@ public class OrcsWriterSheetProcessorForCreateUpdate implements RowProcessor { if (token.getUuid() > 0L) { artifact.setUuid(token.getUuid()); } else { - throw new OseeStateException("Unexpected string [%s] at %s; expected [name]-[uuid] on sheet", - value, OrcsWriterUtil.getRowColumnStr(colCount, colCount), getSheetName()); + throw new OseeStateException("Unexpected string [%s] at %s; expected [name]-[uuid]", value, + OrcsWriterUtil.getRowColumnStr(colCount, colCount, getSheetName())); } } } @@ -198,26 +198,26 @@ public class OrcsWriterSheetProcessorForCreateUpdate implements RowProcessor { if (Strings.isValid(value)) { artifact.setName(value); } else { - throw new OseeStateException("Unexpected Name [%s] at %s on %s sheet", value, - OrcsWriterUtil.getRowColumnStr(colCount, colCount), getSheetName()); + throw new OseeStateException("Unexpected Name [%s] at %s", value, + OrcsWriterUtil.getRowColumnStr(colCount, colCount, getSheetName())); } } if (isAttributeColumn(colCount)) { OwAttributeType attrType = columnToAttributeType.get(colCount); if (attrType.getName().equals(CoreAttributeTypes.Name.getName())) { - throw new OseeStateException("Name cannot also exist as attribute column at %s on %s sheet", - OrcsWriterUtil.getRowColumnStr(rowCount, colCount), getSheetName()); + throw new OseeStateException("Name cannot also exist as attribute column at %s", + OrcsWriterUtil.getRowColumnStr(rowCount, colCount, getSheetName())); } String value = row[colCount]; OwAttribute attr = factory.getOrCreateAttribute(artifact, attrType); attr.getValues().add(value); - attr.setData(OrcsWriterUtil.getData(rowCount, colCount, attr.getData())); + attr.setData(OrcsWriterUtil.getData(getSheetName(), rowCount, colCount, attr.getData())); } else if (isRelationColumn(colCount)) { OwRelationType relType = columnToRelationType.get(colCount); String value = row[colCount]; if (Strings.isValid(value)) { OwRelation relation = factory.createRelationType(relType, value); - relation.setData(OrcsWriterUtil.getData(rowCount, colCount, relation.getData())); + relation.setData(OrcsWriterUtil.getData(getSheetName(), rowCount, colCount, relation.getData())); artifact.getRelations().add(relation); } } diff --git a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/writer/OrcsWriterSheetProcessorForDelete.java b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/writer/OrcsWriterSheetProcessorForDelete.java index 9f51472d1fb..457f5f5d425 100644 --- a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/writer/OrcsWriterSheetProcessorForDelete.java +++ b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/writer/OrcsWriterSheetProcessorForDelete.java @@ -75,7 +75,7 @@ public class OrcsWriterSheetProcessorForDelete implements RowProcessor { artifact = factory.getOrCreateToken(value); } if (artifact != null) { - artifact.setData("Row " + rowCount); + artifact.setData(OrcsWriterUtil.getData(OrcsWriterUtil.DELETE_SHEET_NAME, rowCount, 0, value)); collector.getDelete().add(artifact); } } diff --git a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/writer/OrcsWriterSheetProcessorForSettings.java b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/writer/OrcsWriterSheetProcessorForSettings.java index 72847369854..4b163a5b3e6 100644 --- a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/writer/OrcsWriterSheetProcessorForSettings.java +++ b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/writer/OrcsWriterSheetProcessorForSettings.java @@ -67,7 +67,8 @@ public class OrcsWriterSheetProcessorForSettings implements RowProcessor { if (Strings.isValid(branchTokenStr)) { OwBranch branchToken = factory.getOrCreateBranchToken(branchTokenStr); collector.setBranch(branchToken); - branchToken.setData(OrcsWriterUtil.getData(rowCount, colCount, branchTokenStr)); + branchToken.setData(OrcsWriterUtil.getData(OrcsWriterUtil.INSTRUCTIONS_AND_SETTINGS_SHEET_NAME, rowCount, colCount, + branchTokenStr)); } } else if (key.equals(OrcsWriterUtil.AS_USER_ID_SETTING)) { String userId = row[1]; diff --git a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/writer/OrcsWriterUtil.java b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/writer/OrcsWriterUtil.java index c8ec7b0432d..7d53b557a67 100644 --- a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/writer/OrcsWriterUtil.java +++ b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/writer/OrcsWriterUtil.java @@ -27,16 +27,16 @@ public class OrcsWriterUtil { // Utility Class } - public static String getData(int rowCount, int colCount, String data) { + public static String getData(String sheetName, int rowCount, int colCount, String data) { if (data != null) { data += ", "; } - data += getRowColumnStr(rowCount, colCount); + data += getRowColumnStr(rowCount, colCount, sheetName); return data; } - public static String getRowColumnStr(int rowCount, int colCount) { - return "row " + rowCount + ", column " + (colCount + 1); + public static String getRowColumnStr(int rowCount, int colCount, String sheetName) { + return " sheet=" + sheetName + " row=" + rowCount + ", column=" + (colCount + 1); } } diff --git a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/writer/OrcsWriterWorkbookGenerator.java b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/writer/OrcsWriterWorkbookGenerator.java index bb498fb2cef..3a2a26e0197 100644 --- a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/writer/OrcsWriterWorkbookGenerator.java +++ b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/writer/OrcsWriterWorkbookGenerator.java @@ -170,8 +170,6 @@ public class OrcsWriterWorkbookGenerator { private void createDeleteSheet(ISheetWriter writer) throws IOException { writer.startSheet(OrcsWriterUtil.DELETE_SHEET_NAME, deleteSheetHeadings.length); writer.writeRow((Object[]) deleteSheetHeadings); - writer.writeCell("This sheet is not yet implemented"); - writer.endRow(); writer.endSheet(); } diff --git a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/writer/OwFactory.java b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/writer/OwFactory.java index 5eb01a3f0ca..5782d8ff651 100644 --- a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/writer/OwFactory.java +++ b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/writer/OwFactory.java @@ -85,7 +85,8 @@ public class OwFactory { public static OwArtifact createArtifact(IArtifactType artifactType, String name, Long uuid) { OwArtifact artifact = new OwArtifact(); - artifact.setType(OwFactory.createArtifactType(artifactType)); + OwArtifactType owArtType = OwFactory.createArtifactType(artifactType); + artifact.setType(owArtType); if (uuid == null) { uuid = Lib.generateArtifactIdAsInt(); } -- cgit v1.2.3