diff options
author | Angel Avila | 2015-03-19 21:46:26 +0000 |
---|---|---|
committer | Angel Avila | 2015-03-19 21:46:26 +0000 |
commit | 95c16ef37991ee025050151c5a8f912d5bed5075 (patch) | |
tree | 9e058bf0ddcff5d981e1878b2c8443df18dda4fd /plugins | |
parent | f71f302bab10a655709b0dad4248a3391264a7eb (diff) | |
download | org.eclipse.osee-95c16ef37991ee025050151c5a8f912d5bed5075.tar.gz org.eclipse.osee-95c16ef37991ee025050151c5a8f912d5bed5075.tar.xz org.eclipse.osee-95c16ef37991ee025050151c5a8f912d5bed5075.zip |
feature[ats_ATS146073]: Convert BranchExchange Servlet to JAX-RS
Change-Id: I0d659660f60b560f0f998a84ca730f58e619d2e9
Signed-off-by: Angel Avila <angel.avila2@boeing.com>
Diffstat (limited to 'plugins')
10 files changed, 354 insertions, 349 deletions
diff --git a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/data/OseeServerContext.java b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/data/OseeServerContext.java index c0f6aa6eeef..297b93098b2 100644 --- a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/data/OseeServerContext.java +++ b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/data/OseeServerContext.java @@ -19,7 +19,6 @@ public class OseeServerContext { public static final String PROCESS_CONTEXT = "GET.ARTIFACT"; // For backwards compatibility must remain without base context. public static final String MANAGER_CONTEXT = asAbsoluteContext("manager"); - public static final String BRANCH_EXCHANGE_CONTEXT = asAbsoluteContext("branch/exchange"); public static final String SESSION_CONTEXT = asAbsoluteContext("session"); public static final String CLIENT_LOOPBACK_CONTEXT = asAbsoluteContext("client/loopback"); public static final String ARTIFACT_CONTEXT = asAbsoluteContext("artifact"); diff --git a/plugins/org.eclipse.osee.framework.manager.servlet/src/org/eclipse/osee/framework/manager/servlet/BranchExchangeServlet.java b/plugins/org.eclipse.osee.framework.manager.servlet/src/org/eclipse/osee/framework/manager/servlet/BranchExchangeServlet.java deleted file mode 100644 index a45694c0faa..00000000000 --- a/plugins/org.eclipse.osee.framework.manager.servlet/src/org/eclipse/osee/framework/manager/servlet/BranchExchangeServlet.java +++ /dev/null @@ -1,177 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 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; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.util.LinkedList; -import java.util.concurrent.Callable; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import org.eclipse.osee.framework.core.data.IOseeBranch; -import org.eclipse.osee.framework.core.server.ISessionManager; -import org.eclipse.osee.framework.core.server.SecureOseeHttpServlet; -import org.eclipse.osee.framework.jdk.core.type.PropertyStore; -import org.eclipse.osee.framework.jdk.core.util.Lib; -import org.eclipse.osee.framework.manager.servlet.data.HttpBranchExchangeInfo; -import org.eclipse.osee.framework.manager.servlet.internal.ApplicationContextFactory; -import org.eclipse.osee.framework.resource.management.IResource; -import org.eclipse.osee.framework.resource.management.IResourceLocator; -import org.eclipse.osee.framework.resource.management.IResourceManager; -import org.eclipse.osee.logger.Log; -import org.eclipse.osee.orcs.ApplicationContext; -import org.eclipse.osee.orcs.OrcsApi; -import org.eclipse.osee.orcs.OrcsBranch; -import org.eclipse.osee.orcs.search.BranchQuery; -import com.google.common.collect.Lists; - -/** - * @author Roberto E. Escobar - */ -public class BranchExchangeServlet extends SecureOseeHttpServlet { - - private static final long serialVersionUID = -1642995618810911260L; - - private final IResourceManager resourceManager; - private final OrcsApi orcsApi; - - public BranchExchangeServlet(Log logger, ISessionManager sessionManager, IResourceManager resourceManager, OrcsApi orcsApi) { - super(logger, sessionManager); - this.orcsApi = orcsApi; - this.resourceManager = resourceManager; - } - - private ApplicationContext getContext(HttpServletRequest req) { - return ApplicationContextFactory.createContext(getSessionId(req)); - } - - private OrcsBranch getBranchOps(ApplicationContext context) { - return orcsApi.getBranchOps(context); - } - - private BranchQuery getBranchQuery(ApplicationContext context) { - return orcsApi.getQueryFactory(context).branchQuery(); - } - - @Override - protected void doPost(HttpServletRequest req, HttpServletResponse response) throws IOException { - try { - HttpBranchExchangeInfo exchangeInfo = new HttpBranchExchangeInfo(req); - ApplicationContext context = getContext(req); - OrcsBranch branchOps = getBranchOps(context); - switch (exchangeInfo.getFunction()) { - case exportBranch: - executeExport(branchOps, getBranchQuery(context), exchangeInfo, response); - break; - case importBranch: - executeImport(branchOps, getBranchQuery(context), exchangeInfo, response); - break; - case checkExchange: - executeCheckExchange(branchOps, exchangeInfo, response); - default: - break; - } - } catch (Exception ex) { - response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); - response.setContentType("text/plain"); - getLogger().error(ex, "Error processing [%s]", req); - response.getWriter().write(Lib.exceptionToString(ex)); - } - response.getWriter().flush(); - response.getWriter().close(); - } - - private void executeCheckExchange(OrcsBranch orcsBranch, HttpBranchExchangeInfo exchangeInfo, HttpServletResponse response) throws Exception { - int status = HttpServletResponse.SC_INTERNAL_SERVER_ERROR; - StringBuffer message = new StringBuffer(); - - String path = exchangeInfo.getPath(); - IResourceLocator exchangeLocator = resourceManager.getResourceLocator(path); - Callable<URI> callable = orcsBranch.checkBranchExchangeIntegrity(exchangeLocator.getLocation()); - URI verifyUri = callable.call(); - status = HttpServletResponse.SC_ACCEPTED; - message.append(String.format("Verification at: [%s]", verifyUri.toASCIIString())); - - response.setStatus(status); - response.setContentType("text/plain"); - response.getWriter().write(message.toString()); - } - - private void executeExport(OrcsBranch orcsBranch, BranchQuery branchQuery, HttpBranchExchangeInfo exchangeInfo, HttpServletResponse response) throws Exception { - int status = HttpServletResponse.SC_INTERNAL_SERVER_ERROR; - StringBuffer message = new StringBuffer(); - - branchQuery.andUuids(exchangeInfo.getSelectedBranchUuids()).includeArchived().includeDeleted(); - LinkedList<IOseeBranch> branches = Lists.newLinkedList(branchQuery.getResultsAsId()); - - Callable<URI> callable = - orcsBranch.exportBranch(branches, exchangeInfo.getOptions(), exchangeInfo.getExchangeFileName()); - URI exportURI = callable.call(); - - IResourceLocator exchangeLocator = resourceManager.getResourceLocator(exportURI.toASCIIString()); - status = HttpServletResponse.SC_ACCEPTED; - message.append(String.format("Exported: [%s]", exchangeLocator.getLocation().toASCIIString())); - - if (exchangeInfo.isSendExportFile()) { - InputStream exportFileStream = null; - try { - IResource resource = resourceManager.acquire(exchangeLocator, new PropertyStore()); - exportFileStream = resource.getContent(); - response.setStatus(HttpServletResponse.SC_OK); - response.setContentLength(exportFileStream.available()); - response.setCharacterEncoding("ISO-8859-1"); - response.setContentType("application/zip"); - response.setHeader("Content-Disposition", "attachment; filename=" + resource.getName()); - Lib.inputStreamToOutputStream(exportFileStream, response.getOutputStream()); - } finally { - if (exportFileStream != null) { - exportFileStream.close(); - } - } - } - - if (exchangeInfo.isDeleteExportFile()) { - int deleteResult = resourceManager.delete(exchangeLocator); - if (deleteResult == IResourceManager.OK) { - status = HttpServletResponse.SC_ACCEPTED; - } else { - status = HttpServletResponse.SC_INTERNAL_SERVER_ERROR; - message.append(String.format("Error during deletion of: [%s]", - exchangeLocator.getLocation().toASCIIString())); - } - } - response.setStatus(status); - response.setContentType("text/plain"); - response.getWriter().write(message.toString()); - } - - private void executeImport(OrcsBranch orcsBranch, BranchQuery branchQuery, HttpBranchExchangeInfo exchangeInfo, HttpServletResponse response) throws Exception { - - branchQuery.andUuids(exchangeInfo.getSelectedBranchUuids()).includeArchived().includeDeleted(); - LinkedList<IOseeBranch> branches = Lists.newLinkedList(branchQuery.getResultsAsId()); - - IResourceLocator locator = resourceManager.getResourceLocator(exchangeInfo.getPath()); - Callable<URI> callable = orcsBranch.importBranch(locator.getLocation(), branches, exchangeInfo.getOptions()); - URI importURI = callable.call(); - response.setStatus(HttpServletResponse.SC_ACCEPTED); - response.setContentType("text/plain"); - response.getWriter().write(String.format("Successfully imported: [%s]", importURI.toASCIIString())); - } - - @Override - protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { - super.doGet(req, resp); - // Get available export files. - // Get export file metadata for options. - } -} diff --git a/plugins/org.eclipse.osee.framework.manager.servlet/src/org/eclipse/osee/framework/manager/servlet/data/HttpBranchExchangeInfo.java b/plugins/org.eclipse.osee.framework.manager.servlet/src/org/eclipse/osee/framework/manager/servlet/data/HttpBranchExchangeInfo.java deleted file mode 100644 index 28df05e7835..00000000000 --- a/plugins/org.eclipse.osee.framework.manager.servlet/src/org/eclipse/osee/framework/manager/servlet/data/HttpBranchExchangeInfo.java +++ /dev/null @@ -1,109 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 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.data; - -import java.util.ArrayList; -import java.util.Enumeration; -import java.util.List; -import javax.servlet.http.HttpServletRequest; -import org.eclipse.osee.framework.jdk.core.type.PropertyStore; - -/** - * @author Roberto E. Escobar - */ -public class HttpBranchExchangeInfo { - - public enum BranchExchangeFunctions { - exportBranch, - importBranch, - checkExchange; - }; - - private BranchExchangeFunctions function; - private String exchangeFileName; - private String path; - private final List<Long> selectedBranchUuids; - private boolean sendExportFile; - private boolean deleteExportFile; - private final PropertyStore options; - - public HttpBranchExchangeInfo(HttpServletRequest request) throws Exception { - this.options = new PropertyStore(); - this.function = null; - this.selectedBranchUuids = new ArrayList<Long>(); - this.sendExportFile = false; - this.deleteExportFile = false; - this.exchangeFileName = null; - this.path = null; - - Enumeration<String> enumeration = request.getParameterNames(); - while (enumeration.hasMoreElements()) { - String name = enumeration.nextElement(); - String value = request.getParameter(name); - if (name.equalsIgnoreCase("filename")) { - this.exchangeFileName = value; - } else if (name.equalsIgnoreCase("uri")) { - this.path = value; - } else if (name.equalsIgnoreCase("send.export.file")) { - this.sendExportFile = Boolean.valueOf(value); - } else if (name.equalsIgnoreCase("delete.export.file")) { - this.deleteExportFile = Boolean.valueOf(value); - } else if (name.equalsIgnoreCase("function")) { - isFunctionValid(value); - } else if (name.equalsIgnoreCase("branchUuids")) { - for (String entry : value.split(",")) { - selectedBranchUuids.add(new Long(entry)); - } - } else { - options.put(name.toUpperCase(), value); - } - } - } - - public BranchExchangeFunctions getFunction() { - return this.function; - } - - public boolean isSendExportFile() { - return this.sendExportFile; - } - - public boolean isDeleteExportFile() { - return this.deleteExportFile; - } - - public String getExchangeFileName() { - return this.exchangeFileName; - } - - public String getPath() { - return this.path; - } - - public List<Long> getSelectedBranchUuids() { - return this.selectedBranchUuids; - } - - public PropertyStore getOptions() { - return this.options; - } - - private void isFunctionValid(String function) throws Exception { - if (function == null) { - throw new Exception("A 'function' parameter must be defined."); - } - try { - this.function = BranchExchangeFunctions.valueOf(function); - } catch (IllegalArgumentException ex) { - throw new Exception(String.format("[%s] is not a valid function.", function), ex); - } - } -} diff --git a/plugins/org.eclipse.osee.framework.manager.servlet/src/org/eclipse/osee/framework/manager/servlet/internal/ServletRegistrationHandler.java b/plugins/org.eclipse.osee.framework.manager.servlet/src/org/eclipse/osee/framework/manager/servlet/internal/ServletRegistrationHandler.java index 64aadc90cbf..84e68ab8e10 100644 --- a/plugins/org.eclipse.osee.framework.manager.servlet/src/org/eclipse/osee/framework/manager/servlet/internal/ServletRegistrationHandler.java +++ b/plugins/org.eclipse.osee.framework.manager.servlet/src/org/eclipse/osee/framework/manager/servlet/internal/ServletRegistrationHandler.java @@ -21,7 +21,6 @@ import org.eclipse.osee.framework.core.server.OseeHttpServlet; import org.eclipse.osee.framework.manager.servlet.AdminServlet; import org.eclipse.osee.framework.manager.servlet.ArtifactFileServlet; import org.eclipse.osee.framework.manager.servlet.AtsServlet; -import org.eclipse.osee.framework.manager.servlet.BranchExchangeServlet; import org.eclipse.osee.framework.manager.servlet.DataServlet; import org.eclipse.osee.framework.manager.servlet.SessionClientLoopbackServlet; import org.eclipse.osee.framework.manager.servlet.SessionManagementServlet; @@ -105,8 +104,6 @@ public class ServletRegistrationHandler { register(new ArtifactFileServlet(logger, resourceManager, orcsApi, jdbcClient), OseeServerContext.ARTIFACT_CONTEXT); register(new ArtifactFileServlet(logger, resourceManager, orcsApi, jdbcClient), "index"); - register(new BranchExchangeServlet(logger, sessionManager, resourceManager, orcsApi), - OseeServerContext.BRANCH_EXCHANGE_CONTEXT); register(new SessionManagementServlet(logger, sessionManager, authenticationManager, activityLog), OseeServerContext.SESSION_CONTEXT); register(new SessionClientLoopbackServlet(logger, sessionManager), OseeServerContext.CLIENT_LOOPBACK_CONTEXT); diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/exportImport/HttpBranchExchange.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/exportImport/HttpBranchExchange.java index 63d23d0e191..1f0a74c001c 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/exportImport/HttpBranchExchange.java +++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/exportImport/HttpBranchExchange.java @@ -10,75 +10,41 @@ *******************************************************************************/ package org.eclipse.osee.framework.skynet.core.exportImport; -import java.net.URL; -import java.util.HashMap; -import java.util.Map; -import java.util.logging.Level; -import org.eclipse.osee.framework.core.client.ClientSessionManager; -import org.eclipse.osee.framework.core.client.server.HttpUrlBuilderClient; -import org.eclipse.osee.framework.core.data.OseeServerContext; -import org.eclipse.osee.framework.core.exception.OseeExceptions; -import org.eclipse.osee.framework.core.util.HttpProcessor; +import java.util.ArrayList; +import java.util.List; import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; -import org.eclipse.osee.framework.jdk.core.util.Strings; -import org.eclipse.osee.framework.logging.OseeLog; +import org.eclipse.osee.framework.skynet.core.internal.ServiceUtil; +import org.eclipse.osee.jaxrs.client.JaxRsExceptions; +import org.eclipse.osee.orcs.rest.client.OseeClient; +import org.eclipse.osee.orcs.rest.model.BranchEndpoint; +import org.eclipse.osee.orcs.rest.model.BranchImportOptions; /** * @author Roberto E. Escobar */ public class HttpBranchExchange { - private static final String BRANCH_EXPORT = "exportBranch"; - private static final String BRANCH_IMPORT = "importBranch"; - public static void exportBranches(String exportFileName, int... branchUuids) throws OseeCoreException { - Map<String, String> parameters = new HashMap<String, String>(); - parameters.put("function", BRANCH_EXPORT); - if (Strings.isValid(exportFileName)) { - parameters.put("filename", exportFileName); - } - addBranchIds(parameters, branchUuids); - execute(parameters); - } + public static void importBranches(String path, boolean cleanAllBeforeImport, boolean allAsRootBranches, long... branchUuids) throws OseeCoreException { + OseeClient oseeClient = ServiceUtil.getOseeClient(); + BranchEndpoint endpoint = oseeClient.getBranchEndpoint(); - public static void importBranches(String path, boolean cleanAllBeforeImport, boolean allAsRootBranches, int... branchUuids) throws OseeCoreException { - Map<String, String> parameters = new HashMap<String, String>(); - parameters.put("sessionId", ClientSessionManager.getSessionId()); - parameters.put("function", BRANCH_IMPORT); - if (!path.startsWith("exchange://")) { - path = "exchange://" + path; - } - parameters.put("uri", path); - if (allAsRootBranches) { - parameters.put("all_as_root_branches", Boolean.toString(allAsRootBranches)); - } - if (cleanAllBeforeImport) { - parameters.put("clean_before_import", Boolean.toString(cleanAllBeforeImport)); - } - addBranchIds(parameters, branchUuids); - execute(parameters); - } + BranchImportOptions options = new BranchImportOptions(); + options.setExchangeFile(path); + options.setCleanBeforeImport(cleanAllBeforeImport); + options.setAllAsRootBranches(allAsRootBranches); - private static void execute(Map<String, String> parameters) throws OseeCoreException { + if (branchUuids != null && branchUuids.length > 0) { + List<Long> ids = new ArrayList<Long>(); + for (Long entry : branchUuids) { + ids.add(entry); + } + options.setBranchUuids(ids); + } try { - String returnVal = - HttpProcessor.post(new URL(HttpUrlBuilderClient.getInstance().getOsgiServletServiceUrl( - OseeServerContext.BRANCH_EXCHANGE_CONTEXT, parameters))); - OseeLog.log(HttpBranchExchange.class, Level.INFO, returnVal); + endpoint.importBranches(options); } catch (Exception ex) { - OseeExceptions.wrapAndThrow(ex); + throw JaxRsExceptions.asOseeException(ex); } } - private static void addBranchIds(Map<String, String> parameters, int... branchUuids) { - if (branchUuids != null && branchUuids.length > 0) { - StringBuffer ids = new StringBuffer(); - for (int index = 0; index < branchUuids.length; index++) { - ids.append(branchUuids[index]); - if (index + 1 < branchUuids.length) { - ids.append(","); - } - } - parameters.put("branchUuids", ids.toString()); - } - } } diff --git a/plugins/org.eclipse.osee.orcs.rest.model/src/org/eclipse/osee/orcs/rest/model/BranchEndpoint.java b/plugins/org.eclipse.osee.orcs.rest.model/src/org/eclipse/osee/orcs/rest/model/BranchEndpoint.java index d9ad8d3cbb0..35736ee3cf9 100644 --- a/plugins/org.eclipse.osee.orcs.rest.model/src/org/eclipse/osee/orcs/rest/model/BranchEndpoint.java +++ b/plugins/org.eclipse.osee.orcs.rest.model/src/org/eclipse/osee/orcs/rest/model/BranchEndpoint.java @@ -125,6 +125,24 @@ public interface BranchEndpoint { @Produces({MediaType.APPLICATION_JSON}) Response writeTx(@PathParam("branch-uuid") long branchUuid, NewTransaction data); + @POST + @Path("exchange/validation") + Response validateExchange(@QueryParam("path") String path); + + @POST + @Path("exchange/export") + @Consumes({MediaType.APPLICATION_JSON}) + Response exportBranches(BranchExportOptions options); + + @POST + @Path("exchange/import") + @Consumes({MediaType.APPLICATION_JSON}) + Response importBranches(BranchImportOptions options); + + @DELETE + @Path("exchange") + Response deleteBranchExchange(@QueryParam("path") String path); + @PUT @Path("{branch-uuid}/name/{branch-name}") Response setBranchName(@PathParam("branch-uuid") long branchUuid, @PathParam("branch-name") String newName); diff --git a/plugins/org.eclipse.osee.orcs.rest.model/src/org/eclipse/osee/orcs/rest/model/BranchExportOptions.java b/plugins/org.eclipse.osee.orcs.rest.model/src/org/eclipse/osee/orcs/rest/model/BranchExportOptions.java new file mode 100644 index 00000000000..a0cc2bcd38b --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.rest.model/src/org/eclipse/osee/orcs/rest/model/BranchExportOptions.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * Copyright (c) 2015 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; + +import java.util.Collections; +import java.util.List; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * @author Roberto E. Escobar + */ +@XmlRootElement +public class BranchExportOptions { + + private List<Long> branchUuids; + private long minTx = -1L; + private long maxTx = -1L; + private String filename; + private boolean compress; + + public List<Long> getBranchUuids() { + return branchUuids != null ? branchUuids : Collections.<Long> emptyList(); + } + + public long getMinTx() { + return minTx; + } + + public long getMaxTx() { + return maxTx; + } + + public String getFileName() { + return filename; + } + + public boolean isCompress() { + return compress; + } + + public void setBranchUuids(List<Long> branchUuids) { + this.branchUuids = branchUuids; + } + + public void setMinTx(long minTx) { + this.minTx = minTx; + } + + public void setMaxTx(long maxTx) { + this.maxTx = maxTx; + } + + public void setFileName(String filename) { + this.filename = filename; + } + + public void setCompress(boolean compress) { + this.compress = compress; + } + +} diff --git a/plugins/org.eclipse.osee.orcs.rest.model/src/org/eclipse/osee/orcs/rest/model/BranchImportOptions.java b/plugins/org.eclipse.osee.orcs.rest.model/src/org/eclipse/osee/orcs/rest/model/BranchImportOptions.java new file mode 100644 index 00000000000..3f593ce2f52 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.rest.model/src/org/eclipse/osee/orcs/rest/model/BranchImportOptions.java @@ -0,0 +1,96 @@ +/******************************************************************************* + * Copyright (c) 2015 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; + +import java.util.Collections; +import java.util.List; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * @author Roberto E. Escobar + */ +@XmlRootElement +public class BranchImportOptions { + + private String exchangeFile; + private List<Long> branchUuids; + private long minTx = -1L; + private long maxTx = -1L; + private boolean cleanBeforeImport; + private boolean allAsRootBranches; + private boolean excludeBaselineTxs; + private boolean useIdsFromImportFile; + + public String getExchangeFile() { + return exchangeFile; + } + + public void setExchangeFile(String exchangeFile) { + this.exchangeFile = exchangeFile; + } + + public List<Long> getBranchUuids() { + return branchUuids != null ? branchUuids : Collections.<Long> emptyList(); + } + + public long getMinTx() { + return minTx; + } + + public long getMaxTx() { + return maxTx; + } + + public boolean isCleanBeforeImport() { + return cleanBeforeImport; + } + + public boolean isAllAsRootBranches() { + return allAsRootBranches; + } + + public boolean isExcludeBaselineTxs() { + return excludeBaselineTxs; + } + + public boolean isUseIdsFromImportFile() { + return useIdsFromImportFile; + } + + public void setBranchUuids(List<Long> branchUuids) { + this.branchUuids = branchUuids; + } + + public void setMinTx(long minTx) { + this.minTx = minTx; + } + + public void setMaxTx(long maxTx) { + this.maxTx = maxTx; + } + + public void setCleanBeforeImport(boolean cleanBeforeImport) { + this.cleanBeforeImport = cleanBeforeImport; + } + + public void setAllAsRootBranches(boolean allAsRootBranches) { + this.allAsRootBranches = allAsRootBranches; + } + + public void setExcludeBaselineTxs(boolean excludeBaselineTxs) { + this.excludeBaselineTxs = excludeBaselineTxs; + } + + public void setUseIdsFromImportFile(boolean useIdsFromImportFile) { + this.useIdsFromImportFile = useIdsFromImportFile; + } + +} 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 bf41460e171..72ca215901b 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 @@ -19,6 +19,8 @@ import static org.eclipse.osee.orcs.rest.internal.OrcsRestUtil.asTransaction; import static org.eclipse.osee.orcs.rest.internal.OrcsRestUtil.asTransactions; import static org.eclipse.osee.orcs.rest.internal.OrcsRestUtil.executeCallable; import java.net.URI; +import java.util.Collection; +import java.util.Collections; import java.util.HashSet; import java.util.LinkedList; import java.util.List; @@ -36,13 +38,18 @@ import org.eclipse.osee.framework.core.enums.BranchState; import org.eclipse.osee.framework.core.enums.BranchType; import org.eclipse.osee.framework.core.enums.CoreBranches; import org.eclipse.osee.framework.core.model.change.ChangeItem; +import org.eclipse.osee.framework.jdk.core.type.PropertyStore; import org.eclipse.osee.framework.jdk.core.type.ResultSet; import org.eclipse.osee.framework.jdk.core.util.Compare; import org.eclipse.osee.framework.jdk.core.util.Conditions; import org.eclipse.osee.framework.jdk.core.util.Lib; import org.eclipse.osee.framework.jdk.core.util.Strings; +import org.eclipse.osee.framework.resource.management.IResourceLocator; +import org.eclipse.osee.framework.resource.management.IResourceManager; import org.eclipse.osee.jaxrs.OseeWebApplicationException; import org.eclipse.osee.orcs.ApplicationContext; +import org.eclipse.osee.orcs.ExportOptions; +import org.eclipse.osee.orcs.ImportOptions; import org.eclipse.osee.orcs.OrcsApi; import org.eclipse.osee.orcs.OrcsBranch; import org.eclipse.osee.orcs.data.ArchiveOperation; @@ -53,6 +60,8 @@ import org.eclipse.osee.orcs.data.TransactionReadable; import org.eclipse.osee.orcs.rest.model.Branch; import org.eclipse.osee.orcs.rest.model.BranchCommitOptions; import org.eclipse.osee.orcs.rest.model.BranchEndpoint; +import org.eclipse.osee.orcs.rest.model.BranchExportOptions; +import org.eclipse.osee.orcs.rest.model.BranchImportOptions; import org.eclipse.osee.orcs.rest.model.BranchQueryData; import org.eclipse.osee.orcs.rest.model.CompareResults; import org.eclipse.osee.orcs.rest.model.NewBranch; @@ -73,12 +82,14 @@ import com.google.common.collect.Sets.SetView; public class BranchEndpointImpl implements BranchEndpoint { private final OrcsApi orcsApi; + private final IResourceManager resourceManager; @Context private UriInfo uriInfo; - public BranchEndpointImpl(OrcsApi orcsApi) { + public BranchEndpointImpl(OrcsApi orcsApi, IResourceManager resourceManager) { this.orcsApi = orcsApi; + this.resourceManager = resourceManager; } public void setUriInfo(UriInfo uriInfo) { @@ -377,6 +388,140 @@ public class BranchEndpointImpl implements BranchEndpoint { } @Override + public Response validateExchange(String path) { + String exchangePath = asExchangeLocator(path); + IResourceLocator locator = resourceManager.getResourceLocator(exchangePath); + Callable<URI> op = getBranchOps().checkBranchExchangeIntegrity(locator.getLocation()); + URI verifyUri = executeCallable(op); + + UriInfo uriInfo = getUriInfo(); + URI location = getExchangeResourceURI(uriInfo, verifyUri); + return Response.created(location).build(); + } + + @Override + public Response deleteBranchExchange(String path) { + boolean modified = false; + String exchangePath = asExchangeLocator(path); + IResourceLocator locator = resourceManager.getResourceLocator(exchangePath); + if (locator != null) { + int deleteResult = resourceManager.delete(locator); + switch (deleteResult) { + case IResourceManager.OK: + modified = true; + break; + case IResourceManager.FAIL: + throw new OseeWebApplicationException(Status.INTERNAL_SERVER_ERROR, + "Error deleting exchange resource [%s] - locator [%s]", path, locator.getLocation()); + case IResourceManager.RESOURCE_NOT_FOUND: + default: + // do nothing - no modification + break; + } + } + return OrcsRestUtil.asResponse(modified); + } + + @Override + public Response exportBranches(BranchExportOptions options) { + List<IOseeBranch> branches = getExportImportBranches(options.getBranchUuids()); + + PropertyStore exportOptions = new PropertyStore(); + addOption(exportOptions, ExportOptions.MIN_TXS, options.getMinTx()); + addOption(exportOptions, ExportOptions.MAX_TXS, options.getMaxTx()); + addOption(exportOptions, ExportOptions.COMPRESS, options.isCompress()); + + Callable<URI> op = getBranchOps().exportBranch(branches, exportOptions, options.getFileName()); + URI exportURI = executeCallable(op); + + UriInfo uriInfo = getUriInfo(); + URI location = getExchangeExportUri(uriInfo, exportURI, options.isCompress()); + return Response.created(location).build(); + } + + @Override + public Response importBranches(BranchImportOptions options) { + List<IOseeBranch> branches; + if (!options.getBranchUuids().isEmpty()) { + branches = getExportImportBranches(options.getBranchUuids()); + } else { + branches = Collections.emptyList(); + } + String path = options.getExchangeFile(); + String exchangePath = asExchangeLocator(path); + + IResourceLocator locator = resourceManager.getResourceLocator(exchangePath); + + PropertyStore importOptions = new PropertyStore(); + addOption(importOptions, ImportOptions.MIN_TXS, options.getMinTx()); + addOption(importOptions, ImportOptions.MAX_TXS, options.getMaxTx()); + addOption(importOptions, ImportOptions.USE_IDS_FROM_IMPORT_FILE, options.isUseIdsFromImportFile()); + addOption(importOptions, ImportOptions.EXCLUDE_BASELINE_TXS, options.isExcludeBaselineTxs()); + addOption(importOptions, ImportOptions.ALL_AS_ROOT_BRANCHES, options.isAllAsRootBranches()); + addOption(importOptions, ImportOptions.CLEAN_BEFORE_IMPORT, options.isCleanBeforeImport()); + + Callable<URI> op = getBranchOps().importBranch(locator.getLocation(), branches, importOptions); + URI importURI = executeCallable(op); + + Response response; + if (importURI != null) { + UriInfo uriInfo = getUriInfo(); + URI location = getExchangeResourceURI(uriInfo, importURI); + response = Response.created(location).build(); + } else { + response = Response.ok().build(); + } + return response; + } + + private void addOption(PropertyStore data, Enum<?> enumKey, Object value) { + if (value != null) { + data.put(enumKey.name(), String.valueOf(value)); + } + } + + private String asExchangeLocator(String path) { + String toReturn = path; + if (Strings.isValid(toReturn)) { + if (!toReturn.startsWith("exchange://")) { + toReturn = "exchange://" + toReturn; + } + } + return toReturn; + } + + private URI getExchangeResourceURI(UriInfo uriInfo, URI rawUri) { + URI toReturn = rawUri; + String path = rawUri.toASCIIString(); + int index = path.indexOf("exchange/"); + if (index > 0 && index < path.length()) { + path = path.substring(index); + toReturn = uriInfo.getBaseUriBuilder().path("resources").queryParam("path", path).build(); + } + return toReturn; + } + + private URI getExchangeExportUri(UriInfo uriInfo, URI rawUri, boolean isCompressed) { + String path = rawUri.toASCIIString(); + path = path.replace("://", "/"); + if (isCompressed && !path.endsWith(".zip")) { + path = path + ".zip"; + } else { + path = path + "/export.manifest.xml"; + } + URI toReturn = uriInfo.getBaseUriBuilder().path("resources").queryParam("path", path).build(); + return toReturn; + } + + private List<IOseeBranch> getExportImportBranches(Collection<Long> branchUids) { + ResultSet<IOseeBranch> resultsAsId = newBranchQuery().andUuids(branchUids) // + .includeArchived()// + .includeDeleted()// + .getResultsAsId(); + return Lists.newLinkedList(resultsAsId); + } + + @Override public Response setBranchName(long branchUuid, String newName) { BranchReadable branch = getBranchById(branchUuid); boolean modified = false; @@ -567,4 +712,5 @@ public class BranchEndpointImpl implements BranchEndpoint { } return query.getResults(); } + } diff --git a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/OrcsApplication.java b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/OrcsApplication.java index 7225951287b..076c55a974d 100644 --- a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/OrcsApplication.java +++ b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/OrcsApplication.java @@ -51,7 +51,7 @@ public class OrcsApplication extends Application { classes.add(BranchesResource.class); resources.add(new IdeClientEndpointImpl()); - resources.add(new BranchEndpointImpl(orcsApi)); + resources.add(new BranchEndpointImpl(orcsApi, resourceManager)); resources.add(new TransactionEndpointImpl(orcsApi)); resources.add(new TypesEndpointImpl(orcsApi)); |