diff options
Diffstat (limited to 'plugins/org.eclipse.osee.framework.manager.servlet/src/org/eclipse/osee/framework/manager/servlet/ats/AtsService.java')
-rw-r--r-- | plugins/org.eclipse.osee.framework.manager.servlet/src/org/eclipse/osee/framework/manager/servlet/ats/AtsService.java | 252 |
1 files changed, 126 insertions, 126 deletions
diff --git a/plugins/org.eclipse.osee.framework.manager.servlet/src/org/eclipse/osee/framework/manager/servlet/ats/AtsService.java b/plugins/org.eclipse.osee.framework.manager.servlet/src/org/eclipse/osee/framework/manager/servlet/ats/AtsService.java index ac9afc923ee..ecba78f568e 100644 --- a/plugins/org.eclipse.osee.framework.manager.servlet/src/org/eclipse/osee/framework/manager/servlet/ats/AtsService.java +++ b/plugins/org.eclipse.osee.framework.manager.servlet/src/org/eclipse/osee/framework/manager/servlet/ats/AtsService.java @@ -26,130 +26,130 @@ import org.w3c.dom.Node; */ public class AtsService { - private static enum DataTypeEnum { - PROGRAM, - BUILD, - WORKFLOW; - - public String asFileName() { - return "ats." + this.name().toLowerCase() + ".data.xml"; - } - } - - public static interface IResourceProvider { - IResource getResource(String typeName) throws OseeCoreException; - } - - private final IResourceProvider resourceProvider; - private final AtsXmlSearch xmlSearch; - private final AtsXmlMessages messages; - private final IResourceLocatorManager locatorManager; - private final IResourceManager resourceManager; - - public AtsService(IResourceProvider resourceProvider, AtsXmlSearch xmlSearch, AtsXmlMessages messages, IResourceLocatorManager locatorManager, IResourceManager resourceManager) { - super(); - this.xmlSearch = xmlSearch; - this.messages = messages; - this.resourceProvider = resourceProvider; - this.locatorManager = locatorManager; - this.resourceManager = resourceManager; - } - - public void performOperation(IResource resource, HttpServletResponse response) { - try { - Collection<OperationData> requests = OperationData.fromResource(resource); - for (OperationData data : requests) { - switch (data.getOperationType()) { - case GET_BUILDS_BY_PROGRAM_ID: - getBuilds(response, data.getProgramId()); - break; - case GET_CHANGE_REPORTS_BY_IDS: - getChangeReport(response, data.getItemIds()); - break; - case GET_PROGRAMS: - getPrograms(response); - break; - case GET_WORKFLOWS_BY_IDS: - getWorkflowsById(response, data.getItemIds()); - break; - case GET_WORKFLOWS_BY_PROGRAM_AND_BUILD_ID: - getWorkflowsByProgramAndBuild(response, data.getProgramId(), data.getBuildId()); - break; - default: - throw new UnsupportedOperationException(); - } - } - } catch (Exception ex) { - messages.sendError(response, ex); - } - } - - private IResource getResource(DataTypeEnum fileType) throws OseeCoreException { - return getResource(fileType.asFileName()); - } - - private IResource getResource(String resource) throws OseeCoreException { - String urlPath = String.format("%s://%s", AtsResourceLocatorProvider.PROTOCOL, resource); - return resourceProvider.getResource(urlPath); - } - - public void getPrograms(HttpServletResponse response) throws OseeCoreException { - IResource resource = getResource(DataTypeEnum.PROGRAM); - Collection<Node> nodes = xmlSearch.findPrograms(resource); - messages.sendPrograms(response, nodes); - } - - public void getBuilds(HttpServletResponse response, String programId) throws OseeCoreException { - IResource resource = getResource(DataTypeEnum.BUILD); - Collection<Node> nodes = xmlSearch.findBuildsByProgramId(resource, programId); - messages.sendBuilds(response, nodes); - } - - public void getWorkflowsById(HttpServletResponse response, String idSearch) throws OseeCoreException { - IResource resource = getResource(DataTypeEnum.WORKFLOW); - Collection<Node> nodes = xmlSearch.findWorkflowsById(resource, idSearch); - messages.sendWorkflows(response, nodes); - } - - public void getWorkflowsByProgramAndBuild(HttpServletResponse response, String programId, String buildId) throws OseeCoreException { - IResource resource = getResource(DataTypeEnum.WORKFLOW); - Collection<Node> nodes = xmlSearch.findWorkflowsByProgramAndBuild(resource, programId, buildId); - messages.sendWorkflows(response, nodes); - } - - public void getChangeReport(HttpServletResponse response, String idSearch) throws OseeCoreException { - IResource resource = getResource(DataTypeEnum.WORKFLOW); - Collection<Node> nodes = xmlSearch.findWorkflowsById(resource, idSearch); - messages.sendChangeReports(response, nodes); - } - - public void sendClient(HttpServletRequest request, HttpServletResponse response) { - String urlPath = request.getParameter("url"); - boolean wasErrorSent = false; - IResource resource = null; - try { - if (Strings.isValid(urlPath)) { - resource = resourceProvider.getResource(urlPath); - } else { - String servletPath = request.getServletPath(); - urlPath = request.getRequestURI().replace(servletPath, ""); - - if (urlPath.contains("osee/data")) { - DataServlet.handleUriRequest(locatorManager, resourceManager, urlPath, response); - return; - } else { - resource = getResource(urlPath); - } - } - } catch (OseeCoreException ex) { - messages.sendError(response, ex); - wasErrorSent = true; - } - - if (resource == null && !wasErrorSent) { - messages.sendError(response, new Exception(String.format("Resource not found - [%s]", urlPath))); - } else { - messages.sendResource(response, resource.getName(), resource); - } - } + private static enum DataTypeEnum { + PROGRAM, + BUILD, + WORKFLOW; + + public String asFileName() { + return "ats." + this.name().toLowerCase() + ".data.xml"; + } + } + + public static interface IResourceProvider { + IResource getResource(String typeName) throws OseeCoreException; + } + + private final IResourceProvider resourceProvider; + private final AtsXmlSearch xmlSearch; + private final AtsXmlMessages messages; + private final IResourceLocatorManager locatorManager; + private final IResourceManager resourceManager; + + public AtsService(IResourceProvider resourceProvider, AtsXmlSearch xmlSearch, AtsXmlMessages messages, IResourceLocatorManager locatorManager, IResourceManager resourceManager) { + super(); + this.xmlSearch = xmlSearch; + this.messages = messages; + this.resourceProvider = resourceProvider; + this.locatorManager = locatorManager; + this.resourceManager = resourceManager; + } + + public void performOperation(IResource resource, HttpServletResponse response) { + try { + Collection<OperationData> requests = OperationData.fromResource(resource); + for (OperationData data : requests) { + switch (data.getOperationType()) { + case GET_BUILDS_BY_PROGRAM_ID: + getBuilds(response, data.getProgramId()); + break; + case GET_CHANGE_REPORTS_BY_IDS: + getChangeReport(response, data.getItemIds()); + break; + case GET_PROGRAMS: + getPrograms(response); + break; + case GET_WORKFLOWS_BY_IDS: + getWorkflowsById(response, data.getItemIds()); + break; + case GET_WORKFLOWS_BY_PROGRAM_AND_BUILD_ID: + getWorkflowsByProgramAndBuild(response, data.getProgramId(), data.getBuildId()); + break; + default: + throw new UnsupportedOperationException(); + } + } + } catch (Exception ex) { + messages.sendError(response, ex); + } + } + + private IResource getResource(DataTypeEnum fileType) throws OseeCoreException { + return getResource(fileType.asFileName()); + } + + private IResource getResource(String resource) throws OseeCoreException { + String urlPath = String.format("%s://%s", AtsResourceLocatorProvider.PROTOCOL, resource); + return resourceProvider.getResource(urlPath); + } + + public void getPrograms(HttpServletResponse response) throws OseeCoreException { + IResource resource = getResource(DataTypeEnum.PROGRAM); + Collection<Node> nodes = xmlSearch.findPrograms(resource); + messages.sendPrograms(response, nodes); + } + + public void getBuilds(HttpServletResponse response, String programId) throws OseeCoreException { + IResource resource = getResource(DataTypeEnum.BUILD); + Collection<Node> nodes = xmlSearch.findBuildsByProgramId(resource, programId); + messages.sendBuilds(response, nodes); + } + + public void getWorkflowsById(HttpServletResponse response, String idSearch) throws OseeCoreException { + IResource resource = getResource(DataTypeEnum.WORKFLOW); + Collection<Node> nodes = xmlSearch.findWorkflowsById(resource, idSearch); + messages.sendWorkflows(response, nodes); + } + + public void getWorkflowsByProgramAndBuild(HttpServletResponse response, String programId, String buildId) throws OseeCoreException { + IResource resource = getResource(DataTypeEnum.WORKFLOW); + Collection<Node> nodes = xmlSearch.findWorkflowsByProgramAndBuild(resource, programId, buildId); + messages.sendWorkflows(response, nodes); + } + + public void getChangeReport(HttpServletResponse response, String idSearch) throws OseeCoreException { + IResource resource = getResource(DataTypeEnum.WORKFLOW); + Collection<Node> nodes = xmlSearch.findWorkflowsById(resource, idSearch); + messages.sendChangeReports(response, nodes); + } + + public void sendClient(HttpServletRequest request, HttpServletResponse response) { + String urlPath = request.getParameter("url"); + boolean wasErrorSent = false; + IResource resource = null; + try { + if (Strings.isValid(urlPath)) { + resource = resourceProvider.getResource(urlPath); + } else { + String servletPath = request.getServletPath(); + urlPath = request.getRequestURI().replace(servletPath, ""); + + if (urlPath.contains("osee/data")) { + DataServlet.handleUriRequest(locatorManager, resourceManager, urlPath, response); + return; + } else { + resource = getResource(urlPath); + } + } + } catch (OseeCoreException ex) { + messages.sendError(response, ex); + wasErrorSent = true; + } + + if (resource == null && !wasErrorSent) { + messages.sendError(response, new Exception(String.format("Resource not found - [%s]", urlPath))); + } else { + messages.sendResource(response, resource.getName(), resource); + } + } } |