Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDominic Guss2021-01-07 18:03:18 +0000
committerRyan T. Baldwin2021-01-07 18:03:18 +0000
commit4153c2f12f20eff8232c495e8edccbe273e33fab (patch)
treea3aadc4d734186cedcfee39dbd1b40f52956db81 /plugins/org.eclipse.osee.orcs.rest
parentb71f906b65260abbde157da3c29ea77e25c8214e (diff)
downloadorg.eclipse.osee-4153c2f12f20eff8232c495e8edccbe273e33fab.tar.gz
org.eclipse.osee-4153c2f12f20eff8232c495e8edccbe273e33fab.tar.xz
org.eclipse.osee-4153c2f12f20eff8232c495e8edccbe273e33fab.zip
feature[TW18768]: Update unit tests for asynchronous branch archiving
Change-Id: I9c57280bbc5930f7cc528c8b9a21007e8816cd88 Signed-off-by: Dominic Guss <Dominic.Guss@boeing.com>
Diffstat (limited to 'plugins/org.eclipse.osee.orcs.rest')
-rw-r--r--plugins/org.eclipse.osee.orcs.rest/META-INF/MANIFEST.MF1
-rw-r--r--plugins/org.eclipse.osee.orcs.rest/OSGI-INF/orcs.support.email.service.xml6
-rw-r--r--plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/BranchEndpointImpl.java63
-rw-r--r--plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/branch/UpdateBranchOperation.java4
-rw-r--r--plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/email/SupportEmailService.java75
5 files changed, 122 insertions, 27 deletions
diff --git a/plugins/org.eclipse.osee.orcs.rest/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.orcs.rest/META-INF/MANIFEST.MF
index 5746bdf66a0..f1fe5d6cc71 100644
--- a/plugins/org.eclipse.osee.orcs.rest/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.osee.orcs.rest/META-INF/MANIFEST.MF
@@ -44,6 +44,7 @@ Import-Package: com.fasterxml.jackson.core,
org.eclipse.osee.jaxrs,
org.eclipse.osee.jaxrs.mvc,
org.eclipse.osee.jdbc,
+ org.eclipse.osee.mail.api,
org.eclipse.osee.orcs,
org.eclipse.osee.orcs.core.ds,
org.eclipse.osee.orcs.data,
diff --git a/plugins/org.eclipse.osee.orcs.rest/OSGI-INF/orcs.support.email.service.xml b/plugins/org.eclipse.osee.orcs.rest/OSGI-INF/orcs.support.email.service.xml
new file mode 100644
index 00000000000..5c290557f91
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.rest/OSGI-INF/orcs.support.email.service.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" activate="start">
+ <implementation class="org.eclipse.osee.orcs.rest.internal.email.SupportEmailService"/>
+<reference bind="setMailService" cardinality="1..1" interface="org.eclipse.osee.mail.api.MailService" name="MailService" policy="static"/>
+<reference bind="setOrcsApi" cardinality="1..1" interface="org.eclipse.osee.orcs.OrcsApi" name="OrcsApi" policy="static"/>
+</scr:component>
diff --git a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/BranchEndpointImpl.java b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/BranchEndpointImpl.java
index 3e2dd7cc54d..306a0cb1253 100644
--- a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/BranchEndpointImpl.java
+++ b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/BranchEndpointImpl.java
@@ -30,6 +30,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Callable;
+import java.util.logging.Level;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
@@ -87,6 +88,7 @@ import org.eclipse.osee.orcs.data.AttributeReadable;
import org.eclipse.osee.orcs.data.CreateBranchData;
import org.eclipse.osee.orcs.data.TransactionReadable;
import org.eclipse.osee.orcs.rest.internal.branch.UpdateBranchOperation;
+import org.eclipse.osee.orcs.rest.internal.email.SupportEmailService;
import org.eclipse.osee.orcs.rest.model.BranchCommitOptions;
import org.eclipse.osee.orcs.rest.model.BranchEndpoint;
import org.eclipse.osee.orcs.rest.model.BranchExportOptions;
@@ -110,6 +112,7 @@ public class BranchEndpointImpl implements BranchEndpoint {
private final IResourceManager resourceManager;
private final ActivityLog activityLog;
private final OrcsBranch branchOps;
+ private final SupportEmailService supportEmailService;
@Context
private UriInfo uriInfo;
@@ -122,6 +125,7 @@ public class BranchEndpointImpl implements BranchEndpoint {
this.resourceManager = resourceManager;
this.activityLog = activityLog;
this.branchOps = orcsApi.getBranchOps();
+ this.supportEmailService = new SupportEmailService();
}
public HttpHeaders getHeaders() {
@@ -413,11 +417,17 @@ public class BranchEndpointImpl implements BranchEndpoint {
@Override
public Response archiveBranch(BranchId branchId) {
Branch branch = getBranchById(branchId);
-
boolean modified = false;
if (!branch.isArchived()) {
- Callable<?> op = branchOps.archiveUnarchiveBranch(branch, ArchiveOperation.ARCHIVE);
- executeCallable(op);
+ try {
+ Callable<?> op = branchOps.archiveUnarchiveBranch(branch, ArchiveOperation.ARCHIVE);
+ executeCallable(op);
+ } catch (Exception ex) {
+ supportEmailService.sendSupportEmail("Exception caught during archival of branch " + branchId.getIdString(),
+ ex.getLocalizedMessage());
+ OseeLog.log(ActivityLog.class, Level.SEVERE, ex);
+ return asResponse(modified);
+ }
modified = true;
try {
activityLog.createEntry(BRANCH_OPERATION, ActivityLog.INITIAL_STATUS,
@@ -430,6 +440,32 @@ public class BranchEndpointImpl implements BranchEndpoint {
}
@Override
+ public Response unarchiveBranch(BranchId branchId) {
+ Branch branch = getBranchById(branchId);
+
+ boolean modified = false;
+ if (branch.isArchived()) {
+ try {
+ Callable<?> op = branchOps.archiveUnarchiveBranch(branch, ArchiveOperation.UNARCHIVE);
+ executeCallable(op);
+ } catch (Exception ex) {
+ supportEmailService.sendSupportEmail(
+ "Exception caught during unarchival of branch " + branchId.getIdString(), ex.getLocalizedMessage());
+ OseeLog.log(ActivityLog.class, Level.SEVERE, ex);
+ return asResponse(modified);
+ }
+ modified = true;
+ try {
+ activityLog.createEntry(BRANCH_OPERATION, ActivityLog.INITIAL_STATUS,
+ String.format("Branch Operation Unarchive Branch {branchId: %s}", branchId));
+ } catch (OseeCoreException ex) {
+ OseeLog.log(ActivityLog.class, OseeLevel.SEVERE_POPUP, ex);
+ }
+ }
+ return asResponse(modified);
+ }
+
+ @Override
public Response writeTx(BranchId branch, NewTransaction data) {
String comment = data.getComment();
@@ -725,25 +761,6 @@ public class BranchEndpointImpl implements BranchEndpoint {
}
@Override
- public Response unarchiveBranch(BranchId branchId) {
- Branch branch = getBranchById(branchId);
-
- boolean modified = false;
- if (branch.isArchived()) {
- Callable<?> op = branchOps.archiveUnarchiveBranch(branch, ArchiveOperation.UNARCHIVE);
- executeCallable(op);
- modified = true;
- try {
- activityLog.createEntry(BRANCH_OPERATION, ActivityLog.INITIAL_STATUS,
- String.format("Branch Operation Unarchive Branch {branchId: %s}", branchId));
- } catch (OseeCoreException ex) {
- OseeLog.log(ActivityLog.class, OseeLevel.SEVERE_POPUP, ex);
- }
- }
- return asResponse(modified);
- }
-
- @Override
public Response unCommitBranch(BranchId branch, BranchId destinationBranch) {
throw new UnsupportedOperationException("Not yet implemented");
}
@@ -924,4 +941,4 @@ public class BranchEndpointImpl implements BranchEndpoint {
rel.setTypeId(chStmt.getString("rel_link_type_id"));
return rel;
}
-} \ No newline at end of file
+}
diff --git a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/branch/UpdateBranchOperation.java b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/branch/UpdateBranchOperation.java
index 71e08ac8c5c..7f7977aa16c 100644
--- a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/branch/UpdateBranchOperation.java
+++ b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/branch/UpdateBranchOperation.java
@@ -27,8 +27,6 @@ import org.eclipse.osee.orcs.OrcsApi;
public class UpdateBranchOperation {
private final BranchId toBranchId;
private final BranchId fromBranchId;
- private final String toName;
- private final String fromName;
private final ArtifactId author;
private final UpdateBranchData branchData;
private final OrcsApi orcsApi;
@@ -38,8 +36,6 @@ public class UpdateBranchOperation {
this.toBranchId = branchData.getToBranch();
this.fromBranchId = branchData.getFromBranch();
this.author = branchData.getAuthor();
- this.toName = branchData.getToName();
- this.fromName = branchData.getFromName();
this.branchData = branchData;
}
diff --git a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/email/SupportEmailService.java b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/email/SupportEmailService.java
new file mode 100644
index 00000000000..f2b853f9fab
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/email/SupportEmailService.java
@@ -0,0 +1,75 @@
+/*********************************************************************
+ * Copyright (c) 2021 Boeing
+ *
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ **********************************************************************/
+
+package org.eclipse.osee.orcs.rest.internal.email;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import org.eclipse.osee.framework.core.data.IUserGroup;
+import org.eclipse.osee.framework.core.data.UserToken;
+import org.eclipse.osee.framework.core.enums.CoreUserGroups;
+import org.eclipse.osee.framework.core.util.MailStatus;
+import org.eclipse.osee.framework.jdk.core.util.EmailUtil;
+import org.eclipse.osee.mail.api.MailMessage;
+import org.eclipse.osee.mail.api.MailMessage.MailMessageBuilder;
+import org.eclipse.osee.mail.api.MailService;
+import org.eclipse.osee.orcs.OrcsApi;
+
+/**
+ * @author Dominic Guss
+ */
+public class SupportEmailService {
+
+ private static MailService mailService;
+ private static OrcsApi orcsApi;
+
+ public SupportEmailService() {
+ // Default constructor required. Do nothing
+ }
+
+ public void setOrcsApi(OrcsApi orcsApi) {
+ SupportEmailService.orcsApi = orcsApi;
+ }
+
+ public void setMailService(MailService mailService) {
+ SupportEmailService.mailService = mailService;
+ }
+
+ public List<MailStatus> sendSupportEmail(String subject, String msg) {
+ List<String> recipients = new ArrayList<String>();
+ IUserGroup oseeSupportGroup = orcsApi.getUserGroupService().getUserGroup(CoreUserGroups.OseeSupport);
+ Collection<UserToken> members = oseeSupportGroup.getMembers();
+
+ String email;
+ for (UserToken token : members) {
+ email = token.getEmail();
+ if (EmailUtil.isEmailValid(email)) {
+ recipients.add(email);
+ }
+ }
+
+ List<MailStatus> status = null;
+ if (!recipients.isEmpty()) {
+ MailMessageBuilder builder = MailMessage.newBuilder();
+ builder.addText(msg);
+ builder.subject(subject);
+ builder.replyTo(mailService.getReplyToEmail());
+ builder.from(mailService.getAdminEmail());
+ builder.recipients(recipients);
+ MailMessage message = builder.build();
+ status = mailService.sendMessages(message);
+ }
+ return status;
+ }
+}

Back to the top