/** * The method returns a list of {@link SoapResource} that matches the * search criteria. * * @param soapProjectId The id of the project. * @param types The types of {@link SoapResource} that should be returned. * @return A list of {@link SoapResource} of the specific provided type. * All resources will be returned if the type is null. * @since 1.16 */ @Override public Collection<SoapResource> findSoapResources(final String soapProjectId, final SoapResourceType... types) { Preconditions.checkNotNull(soapProjectId, "Project id cannot be null"); final List<SoapResource> soapResources = new ArrayList<>(); for(SoapResourceFile soapResourceFile : this.collection.values()){ if(soapResourceFile.getProjectId().equals(soapProjectId)){ for(SoapResourceType type : types){ if(type.equals(soapResourceFile.getType())){ SoapResource soapResource = mapper.map(soapResourceFile, SoapResource.class); soapResources.add(soapResource); } } } } return soapResources; }
final SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd-hh-mm-ss"); final Date now = new Date(); final String soapResourceName = soapResource.getType().name() + "-" + formatter.format(now); soapResource.setName(soapResourceName); if(projectId.isPresent()){ if(SoapResourceType.WSDL.equals(soapResource.getType())){
/** * The method loads a resource that matching the search criteria and returns the result * * @param soapResourceId The id of the resource that will be loaded * @return Returns the loaded resource and returns it as a String. * @throws IllegalArgumentException IllegalArgumentException will be thrown jf no matching SOAP operation was found * @see SoapResource * @since 1.16 */ @Override public String loadSoapResource(String soapResourceId) { Preconditions.checkNotNull(soapResourceId, "Resource id cannot be null"); final SoapResourceFile soapResource = this.collection.get(soapResourceId); String path = this.fileDirectory + File.separator; if(SoapResourceType.WSDL.equals(soapResource.getType())){ path += WSDL_DIRECTORY; } else if(SoapResourceType.WSDL.equals(soapResource.getType())){ path += SCHEMA_DIRECTORY; } String resource = fileRepositorySupport.load(path, soapResource.getId() + this.fileExtension); return resource; }
/** * The method returns a list of {@link SoapResource} that matches the * search criteria. * * @param soapProjectId The id of the project. * @param types The types of {@link SoapResource} that should be returned. * @return A list of {@link SoapResource} of the specific provided type. * All resources will be returned if the type is null. */ @Override public Collection<SoapResource> findSoapResources(final String soapProjectId, final SoapResourceType... types) { Preconditions.checkNotNull(soapProjectId, "Project id cannot be null"); List<SoapResourceDocument> resources = mongoOperations.find(getProjectIdQuery(soapProjectId), SoapResourceDocument.class); final List<SoapResource> soapResources = new ArrayList<>(); for (SoapResourceDocument soapResourceDocument : resources) { for (SoapResourceType type : types) { if (type.equals(soapResourceDocument.getType())) { SoapResource soapResource = mapper.map(soapResourceDocument, SoapResource.class); soapResources.add(soapResource); } } } return soapResources; }
/** * Delete an instance that match the provided id * @param id The instance that matches the provided id will be deleted in the database */ @Override public SoapResource delete(final String id) { Preconditions.checkNotNull(id, "Resource id cannot be null"); SoapResourceFile soapResource = this.collection.remove(id); if(soapResource != null){ String path = this.fileDirectory + File.separator; if(SoapResourceType.WSDL.equals(soapResource.getType())){ path += WSDL_DIRECTORY; } else if(SoapResourceType.WSDL.equals(soapResource.getType())){ path += SCHEMA_DIRECTORY; } try { // Try to delete a SOAP resource. // This operation can fail and that is expected. // The reason for this is if you import a project, // it might not have all the resource included. // If that is the case, the we should only log // that we weren't able to delete the resource file. this.fileRepositorySupport.delete(path, soapResource.getId() + this.fileExtension); } catch (IllegalStateException e){ LOGGER.warn("Unable to delete the following SOAP resource: " + id); } } return soapResource != null ? mapper.map(soapResource, SoapResource.class) : null; }
/** * The method adds a new {@link SoapResource}. * * @param soapResource The instance of {@link SoapResource} that will be saved. * @param resource The raw resource * @return The saved {@link SoapResource} * @see SoapResource */ @Override public SoapResource saveSoapResource(SoapResource soapResource, String resource) { SoapResourceFile resourceFile = mapper.map(soapResource, SoapResourceFile.class); SoapResource saveSoapResource = save(soapResource); String path = this.fileDirectory + File.separator; if(SoapResourceType.WSDL.equals(resourceFile.getType())){ path += WSDL_DIRECTORY; } else if(SoapResourceType.WSDL.equals(resourceFile.getType())){ path += SCHEMA_DIRECTORY; } try { this.fileRepositorySupport.save(path, saveSoapResource.getId() + this.fileExtension, resource); } catch (Exception e){ LOGGER.error("Unable to upload SOAP resource", e); } return saveSoapResource; }
private String getWsdl(final String projectId){ final ReadSoapProjectOutput projectOutput = this.serviceProcessor.process(ReadSoapProjectInput.builder() .projectId(projectId) .build()); final SoapProject soapProject = projectOutput.getProject(); return soapProject.getResources().stream() .filter(soapResource -> SoapResourceType.WSDL.equals(soapResource.getType())) .findFirst() .map(soapResource -> { final LoadSoapResourceOutput loadOutput = this.serviceProcessor.process(LoadSoapResourceInput.builder() .projectId(projectId) .resourceId(soapResource.getId()) .build()); return loadOutput.getResource(); }) .orElseThrow(() -> new IllegalArgumentException("Unable to find a WSDL file for the following project: " + projectId)); }