Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoberto E. Escobar2012-09-11 22:09:51 +0000
committerRoberto E. Escobar2012-09-11 22:09:51 +0000
commit02e7e3c897034035c822e6f8cda9859a48ca5c76 (patch)
tree0a60d0378582f6eb2bba38bf614ecafbe33105fa
parent580c0c7e7b74c4b3f1452e4edf443609c1229e83 (diff)
downloadorg.eclipse.osee-02e7e3c897034035c822e6f8cda9859a48ca5c76.tar.gz
org.eclipse.osee-02e7e3c897034035c822e6f8cda9859a48ca5c76.tar.xz
org.eclipse.osee-02e7e3c897034035c822e6f8cda9859a48ca5c76.zip
bug: Fix unsubscribe from group server operation
-rw-r--r--plugins/org.eclipse.osee.framework.manager.servlet/src/org/eclipse/osee/framework/manager/servlet/UnsubscribeData.java31
-rw-r--r--plugins/org.eclipse.osee.framework.manager.servlet/src/org/eclipse/osee/framework/manager/servlet/UnsubscribeParser.java (renamed from plugins/org.eclipse.osee.framework.manager.servlet/src/org/eclipse/osee/framework/manager/servlet/UnsubscribeRequest.java)26
-rw-r--r--plugins/org.eclipse.osee.framework.manager.servlet/src/org/eclipse/osee/framework/manager/servlet/UnsubscribeServlet.java33
-rw-r--r--plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/BranchDataStore.java3
-rw-r--r--plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/transaction/TransactionFactoryImpl.java6
-rw-r--r--plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/branch/BranchDataStoreImpl.java5
-rw-r--r--plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/transaction/UnsubscribeTransaction.java128
-rw-r--r--plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/transaction/TransactionFactory.java3
8 files changed, 199 insertions, 36 deletions
diff --git a/plugins/org.eclipse.osee.framework.manager.servlet/src/org/eclipse/osee/framework/manager/servlet/UnsubscribeData.java b/plugins/org.eclipse.osee.framework.manager.servlet/src/org/eclipse/osee/framework/manager/servlet/UnsubscribeData.java
new file mode 100644
index 00000000000..034bb907526
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.manager.servlet/src/org/eclipse/osee/framework/manager/servlet/UnsubscribeData.java
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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.framework.manager.servlet;
+
+public class UnsubscribeData {
+ private final String groupId;
+ private final String userId;
+
+ public UnsubscribeData(String groupId, String userId) {
+ super();
+ this.groupId = groupId;
+ this.userId = userId;
+ }
+
+ public int getGroupId() {
+ return Integer.parseInt(groupId);
+ }
+
+ public int getUserId() {
+ return Integer.parseInt(userId);
+ }
+
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.osee.framework.manager.servlet/src/org/eclipse/osee/framework/manager/servlet/UnsubscribeRequest.java b/plugins/org.eclipse.osee.framework.manager.servlet/src/org/eclipse/osee/framework/manager/servlet/UnsubscribeParser.java
index bf183e3d802..5cd50d40d3c 100644
--- a/plugins/org.eclipse.osee.framework.manager.servlet/src/org/eclipse/osee/framework/manager/servlet/UnsubscribeRequest.java
+++ b/plugins/org.eclipse.osee.framework.manager.servlet/src/org/eclipse/osee/framework/manager/servlet/UnsubscribeParser.java
@@ -20,35 +20,23 @@ import org.eclipse.osee.framework.jdk.core.util.xml.Jaxp;
import org.eclipse.osee.framework.manager.servlet.ats.XmlUtil;
import org.w3c.dom.Element;
-public final class UnsubscribeRequest {
+public final class UnsubscribeParser {
private static final Matcher URI_PATTERN_MATCHER = Pattern.compile("group/(\\d+)?/user/(\\d+)").matcher("");
- private final String groupId;
- private final String userId;
- public UnsubscribeRequest(String groupId, String userId) {
- super();
- this.groupId = groupId;
- this.userId = userId;
+ private UnsubscribeParser() {
+ // Utility class
}
- public int getGroupId() {
- return Integer.parseInt(groupId);
- }
-
- public int getUserId() {
- return Integer.parseInt(userId);
- }
-
- public static UnsubscribeRequest createFromXML(HttpServletRequest request) throws IOException, Exception {
+ public static UnsubscribeData createFromXML(HttpServletRequest request) throws IOException, Exception {
Element rootElement = XmlUtil.readXML(request.getInputStream());
String groupId = Jaxp.getChildText(rootElement, "groupId");
String userId = Jaxp.getChildText(rootElement, "userId");
Conditions.checkNotNullOrEmpty(groupId, "groupId");
Conditions.checkNotNullOrEmpty(userId, "userId");
- return new UnsubscribeRequest(groupId, userId);
+ return new UnsubscribeData(groupId, userId);
}
- public static UnsubscribeRequest createFromURI(HttpServletRequest request) throws OseeCoreException {
+ public static UnsubscribeData createFromURI(HttpServletRequest request) throws OseeCoreException {
String uri = request.getRequestURI();
String groupId = null;
String userId = null;
@@ -59,6 +47,6 @@ public final class UnsubscribeRequest {
}
Conditions.checkNotNullOrEmpty(groupId, "groupId");
Conditions.checkNotNullOrEmpty(userId, "userId");
- return new UnsubscribeRequest(groupId, userId);
+ return new UnsubscribeData(groupId, userId);
}
} \ No newline at end of file
diff --git a/plugins/org.eclipse.osee.framework.manager.servlet/src/org/eclipse/osee/framework/manager/servlet/UnsubscribeServlet.java b/plugins/org.eclipse.osee.framework.manager.servlet/src/org/eclipse/osee/framework/manager/servlet/UnsubscribeServlet.java
index de1c3f398df..2f4ed565d50 100644
--- a/plugins/org.eclipse.osee.framework.manager.servlet/src/org/eclipse/osee/framework/manager/servlet/UnsubscribeServlet.java
+++ b/plugins/org.eclipse.osee.framework.manager.servlet/src/org/eclipse/osee/framework/manager/servlet/UnsubscribeServlet.java
@@ -13,20 +13,17 @@ package org.eclipse.osee.framework.manager.servlet;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
+import java.util.concurrent.Callable;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import org.eclipse.osee.framework.core.enums.CoreAttributeTypes;
import org.eclipse.osee.framework.core.enums.CoreBranches;
-import org.eclipse.osee.framework.core.enums.CoreRelationTypes;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.server.UnsecuredOseeHttpServlet;
import org.eclipse.osee.framework.jdk.core.util.Lib;
import org.eclipse.osee.logger.Log;
import org.eclipse.osee.orcs.OrcsApi;
import org.eclipse.osee.orcs.data.ArtifactReadable;
-import org.eclipse.osee.orcs.data.GraphReadable;
import org.eclipse.osee.orcs.search.QueryFactory;
-import org.eclipse.osee.orcs.transaction.OrcsTransaction;
import org.eclipse.osee.orcs.transaction.TransactionFactory;
import org.osgi.framework.BundleContext;
@@ -54,7 +51,7 @@ public class UnsubscribeServlet extends UnsecuredOseeHttpServlet {
try {
String requestUri = request.getRequestURL().toString();
requestUri = requestUri.replace(request.getPathInfo(), "");
- UnsubscribeRequest data = UnsubscribeRequest.createFromURI(request);
+ UnsubscribeData data = UnsubscribeParser.createFromURI(request);
String page = createConfirmationPage(requestUri, data);
response.setStatus(HttpServletResponse.SC_OK);
@@ -74,7 +71,7 @@ public class UnsubscribeServlet extends UnsecuredOseeHttpServlet {
response.getWriter().write(ex.toString());
}
- private String createConfirmationPage(String uri, UnsubscribeRequest data) throws IOException {
+ private String createConfirmationPage(String uri, UnsubscribeData data) throws IOException {
URL url = bundleContext.getBundle().getResource("templates/unsubscribeTemplate.html");
InputStream inputStream = null;
try {
@@ -89,27 +86,29 @@ public class UnsubscribeServlet extends UnsecuredOseeHttpServlet {
@Override
protected void doDelete(HttpServletRequest request, HttpServletResponse response) throws IOException {
try {
- UnsubscribeRequest data = UnsubscribeRequest.createFromXML(request);
+ UnsubscribeData data = UnsubscribeParser.createFromXML(request);
QueryFactory queryFactory = getOrcsApi().getQueryFactory(null);
- ArtifactReadable authorArtifact = getArtifactById(queryFactory, data.getUserId());
+ ArtifactReadable userArtifact = getArtifactById(queryFactory, data.getUserId());
ArtifactReadable groupArtifact = getArtifactById(queryFactory, data.getGroupId());
- String comment =
- String.format("UserId [%s] requested unsubscribe from group [%s]",
- authorArtifact.getSoleAttributeAsString(CoreAttributeTypes.UserId), groupArtifact.getName());
+ // String comment =
+ // String.format("UserId [%s] requested unsubscribe from group [%s]",
+ // authorArtifact.getSoleAttributeAsString(CoreAttributeTypes.UserId), groupArtifact.getName());
- GraphReadable readableGraph = orcsApi.getGraph(null);
+ // GraphReadable readableGraph = orcsApi.getGraph(null);
TransactionFactory factory = orcsApi.getTransactionFactory(null);
- OrcsTransaction txn = factory.createTransaction(CoreBranches.COMMON, authorArtifact, comment);
+ Callable<String> callable = factory.createUnsubscribeTx(userArtifact, groupArtifact);
+ String message = callable.call();
+ // OrcsTransaction txn = factory.createTransaction(CoreBranches.COMMON, authorArtifact, comment);
- txn.asWriteableGraph(readableGraph).deleteRelation(groupArtifact, CoreRelationTypes.Users_Artifact,
- authorArtifact);
- txn.commit();
+ // txn.asWriteableGraph(readableGraph).deleteRelation(groupArtifact, CoreRelationTypes.Users_Artifact,
+ // authorArtifact);
+ // txn.commit();
- String message = String.format("<br/>You have been successfully unsubscribed.");
+ // String message = String.format("<br/>You have been successfully unsubscribed.");
response.setStatus(HttpServletResponse.SC_OK);
response.setContentType("text/plain");
diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/BranchDataStore.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/BranchDataStore.java
index b516ecb6545..d43ff2df8ac 100644
--- a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/BranchDataStore.java
+++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/BranchDataStore.java
@@ -46,4 +46,7 @@ public interface BranchDataStore {
Callable<URI> checkBranchExchangeIntegrity(String sessionId, URI fileToCheck);
Callable<TransactionResult> commitTransaction(String sessionId, TransactionData transaction);
+
+ // Temp
+ Callable<String> createUnsubscribeTx(ArtifactReadable userArtifact, ArtifactReadable groupArtifact);
}
diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/transaction/TransactionFactoryImpl.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/transaction/TransactionFactoryImpl.java
index 94aef5b4612..7829c3e4936 100644
--- a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/transaction/TransactionFactoryImpl.java
+++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/transaction/TransactionFactoryImpl.java
@@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.osee.orcs.core.internal.transaction;
+import java.util.concurrent.Callable;
import org.eclipse.osee.framework.core.data.IOseeBranch;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.util.Conditions;
@@ -54,4 +55,9 @@ public class TransactionFactoryImpl implements TransactionFactory {
orcsTxn.setAuthor(author);
return orcsTxn;
}
+
+ @Override
+ public Callable<String> createUnsubscribeTx(ArtifactReadable userArtifact, ArtifactReadable groupArtifact) {
+ return branchDataStore.createUnsubscribeTx(userArtifact, groupArtifact);
+ }
}
diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/branch/BranchDataStoreImpl.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/branch/BranchDataStoreImpl.java
index ed87f032675..dc20ecd30cf 100644
--- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/branch/BranchDataStoreImpl.java
+++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/branch/BranchDataStoreImpl.java
@@ -53,6 +53,7 @@ import org.eclipse.osee.orcs.db.internal.transaction.ComodificationCheck;
import org.eclipse.osee.orcs.db.internal.transaction.TransactionCheck;
import org.eclipse.osee.orcs.db.internal.transaction.TransactionWriter;
import org.eclipse.osee.orcs.db.internal.transaction.TxSqlBuilderImpl;
+import org.eclipse.osee.orcs.db.internal.transaction.UnsubscribeTransaction;
/**
* @author Roberto E. Escobar
@@ -164,4 +165,8 @@ public class BranchDataStoreImpl implements BranchDataStore {
}
}
+ @Override
+ public Callable<String> createUnsubscribeTx(ArtifactReadable userArtifact, ArtifactReadable groupArtifact) {
+ return new UnsubscribeTransaction(logger, dbService, cachingService, identityService, userArtifact, groupArtifact);
+ }
}
diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/transaction/UnsubscribeTransaction.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/transaction/UnsubscribeTransaction.java
new file mode 100644
index 00000000000..442ab207fbb
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/transaction/UnsubscribeTransaction.java
@@ -0,0 +1,128 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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.db.internal.transaction;
+
+import java.sql.Timestamp;
+import org.eclipse.osee.database.schema.DatabaseTxCallable;
+import org.eclipse.osee.framework.core.enums.CoreRelationTypes;
+import org.eclipse.osee.framework.core.enums.ModificationType;
+import org.eclipse.osee.framework.core.enums.TransactionDetailsType;
+import org.eclipse.osee.framework.core.enums.TxChange;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.framework.core.exception.OseeStateException;
+import org.eclipse.osee.framework.core.model.Branch;
+import org.eclipse.osee.framework.core.services.IOseeCachingService;
+import org.eclipse.osee.framework.core.services.IdentityService;
+import org.eclipse.osee.framework.database.IOseeDatabaseService;
+import org.eclipse.osee.framework.database.core.IOseeStatement;
+import org.eclipse.osee.framework.database.core.OseeConnection;
+import org.eclipse.osee.framework.jdk.core.util.Lib;
+import org.eclipse.osee.framework.jdk.core.util.time.GlobalTime;
+import org.eclipse.osee.logger.Log;
+import org.eclipse.osee.orcs.data.ArtifactReadable;
+import org.eclipse.osee.orcs.db.internal.accessor.UpdatePreviousTxCurrent;
+
+public final class UnsubscribeTransaction extends DatabaseTxCallable<String> {
+ private final static String SELECT_RELATION_LINK =
+ "select txs.gamma_id, rel.rel_link_id, txs.mod_type from osee_relation_link rel, osee_txs txs where rel.a_art_id = ? and rel.b_art_id = ? and rel.rel_link_type_id = ? and rel.gamma_id=txs.gamma_id and txs.branch_id = ? and txs.tx_current <> ? order by txs.tx_current";
+ private final static String INSERT_INTO_TX_DETAILS =
+ "insert into osee_tx_details (branch_id, transaction_id, osee_comment, time, author, tx_type) values (?,?,?,?,?,?)";
+ private final static String INSERT_INTO_TXS =
+ "insert into osee_txs (mod_type, tx_current, transaction_id, gamma_id, branch_id) values (?, ?, ?, ?, ?)";
+
+ private Branch common;
+ private int relationId;
+ private int currentGammaId;
+ private final IOseeCachingService cacheService;
+ private final IdentityService identityService;
+ private final ArtifactReadable groupArtifact;
+ private final ArtifactReadable userArtifact;
+ private String completionMethod;
+
+ public UnsubscribeTransaction(Log logger, IOseeDatabaseService databaseService, IOseeCachingService cacheService, IdentityService identityService, ArtifactReadable userArtifact, ArtifactReadable groupArtifact) {
+ super(logger, databaseService, "Delete Relation");
+ this.cacheService = cacheService;
+ this.identityService = identityService;
+
+ this.groupArtifact = groupArtifact;
+ this.userArtifact = userArtifact;
+ }
+
+ private ArtifactReadable getGroup() {
+ return groupArtifact;
+ }
+
+ private ArtifactReadable getUser() {
+ return userArtifact;
+ }
+
+ @Override
+ protected String handleTxWork(OseeConnection connection) throws OseeCoreException {
+ if (getRelationTxData()) {
+ UpdatePreviousTxCurrent txc = new UpdatePreviousTxCurrent(getDatabaseService(), common, connection);
+ txc.addRelation(relationId);
+ txc.updateTxNotCurrents();
+
+ createNewTxAddressing(connection);
+ }
+ return completionMethod;
+ }
+
+ private boolean getRelationTxData() throws OseeCoreException {
+ common = cacheService.getBranchCache().getCommonBranch();
+ int relationTypeId = identityService.getLocalId(CoreRelationTypes.Users_Artifact);
+ IOseeStatement chStmt = getDatabaseService().getStatement();
+
+ try {
+ chStmt.runPreparedQuery(1, SELECT_RELATION_LINK, getGroup().getLocalId(), getUser().getLocalId(),
+ relationTypeId, common.getId(), TxChange.NOT_CURRENT.getValue());
+ if (chStmt.next()) {
+ currentGammaId = chStmt.getInt("gamma_id");
+ relationId = chStmt.getInt("rel_link_id");
+ int modType = chStmt.getInt("mod_type");
+ return ensureNotAlreadyDeleted(modType);
+ } else {
+ throw new OseeStateException(
+ "No existing relation (deleted or otherwise) was found for group [%s] and user [%s].",
+ getGroup().getLocalId(), getGroup().getLocalId());
+ }
+ } finally {
+ Lib.close(chStmt);
+ }
+ }
+
+ private boolean ensureNotAlreadyDeleted(int modType) {
+ if (modType == ModificationType.ARTIFACT_DELETED.getValue() || modType == ModificationType.DELETED.getValue()) {
+ completionMethod =
+ String.format("<br/>You have already been removed from the group.<br/> group [%s] user [%s]", getGroup(),
+ getUser());
+ return false;
+ } else {
+ completionMethod = String.format("<br/>You have been successfully unsubscribed.");
+ return true;
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private void createNewTxAddressing(OseeConnection connection) throws OseeCoreException {
+ int transactionId = getDatabaseService().getSequence().getNextTransactionId();
+ String comment =
+ String.format("User %s requested unsubscribe from group %s", getUser().getLocalId(), getGroup().getLocalId());
+ Timestamp timestamp = GlobalTime.GreenwichMeanTimestamp();
+ int txType = TransactionDetailsType.NonBaselined.getId();
+
+ getDatabaseService().runPreparedUpdate(connection, INSERT_INTO_TX_DETAILS, common.getId(), transactionId,
+ comment, timestamp, getUser().getLocalId(), txType);
+ getDatabaseService().runPreparedUpdate(connection, INSERT_INTO_TXS, ModificationType.DELETED.getValue(),
+ TxChange.DELETED.getValue(), transactionId, currentGammaId, common.getId());
+ }
+
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/transaction/TransactionFactory.java b/plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/transaction/TransactionFactory.java
index de5427132a4..c97fb247120 100644
--- a/plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/transaction/TransactionFactory.java
+++ b/plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/transaction/TransactionFactory.java
@@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.osee.orcs.transaction;
+import java.util.concurrent.Callable;
import org.eclipse.osee.framework.core.data.IOseeBranch;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.orcs.data.ArtifactReadable;
@@ -21,4 +22,6 @@ public interface TransactionFactory {
OrcsTransaction createTransaction(IOseeBranch branch, ArtifactReadable userArtifact, String comment) throws OseeCoreException;
+ // Temp method
+ Callable<String> createUnsubscribeTx(ArtifactReadable userArtifact, ArtifactReadable groupArtifact);
}

Back to the top