protected Map<String, byte[]> getPageResources(BusinessArchive businessArchive) { return businessArchive.getResources(REGEX); }
protected Map<String, byte[]> getPageResources(BusinessArchive businessArchive) { return businessArchive.getResources(REGEX); }
void validateBusinessArchive(BusinessArchive businessArchive) throws ProcessDeployException { for (Map.Entry<String, byte[]> resource : businessArchive.getResources().entrySet()) { final byte[] resourceContent = resource.getValue(); if (resourceContent == null || resourceContent.length == 0) { throw new ProcessDeployException("The BAR file you are trying to deploy contains an empty file: " + resource.getKey() + ". The process cannot be deployed. Fix it or remove it from the BAR."); } } }
@Override public void saveToBarFolder(final BusinessArchive businessArchive, final File barFolder) throws IOException { final File externalResourceFolder = new File(barFolder, EXTERNAL_RESOURCE_FOLDER); externalResourceFolder.mkdir(); final int beginIndex = EXTERNAL_RESOURCE_FOLDER.length(); final Map<String, byte[]> resources = businessArchive.getResources("^" + EXTERNAL_RESOURCE_FOLDER + "/.*$"); for (final Entry<String, byte[]> entry : resources.entrySet()) { final File fullPathFile = new File(externalResourceFolder, entry.getKey().substring(beginIndex)); fullPathFile.getParentFile().mkdirs(); IOUtil.write(fullPathFile, entry.getValue()); } }
@Override public void saveToBarFolder(final BusinessArchive businessArchive, final File barFolder) throws IOException { final File externalResourceFolder = new File(barFolder, EXTERNAL_RESOURCE_FOLDER); externalResourceFolder.mkdir(); final int beginIndex = EXTERNAL_RESOURCE_FOLDER.length(); final Map<String, byte[]> resources = businessArchive.getResources("^" + EXTERNAL_RESOURCE_FOLDER + "/.*$"); for (final Entry<String, byte[]> entry : resources.entrySet()) { final File fullPathFile = new File(externalResourceFolder, entry.getKey().substring(beginIndex)); fullPathFile.getParentFile().mkdirs(); IOUtil.write(fullPathFile, entry.getValue()); } }
void validateBusinessArchive(BusinessArchive businessArchive) throws ProcessDeployException { for (Map.Entry<String, byte[]> resource : businessArchive.getResources().entrySet()) { final byte[] resourceContent = resource.getValue(); if (resourceContent == null || resourceContent.length == 0) { throw new ProcessDeployException("The BAR file you are trying to deploy contains an empty file: " + resource.getKey() + ". The process cannot be deployed. Fix it or remove it from the BAR."); } } }
void saveResources(BusinessArchive businessArchive, SProcessDefinition processDefinition, String folder, BARResourceType type) throws SRecorderException { final Map<String, byte[]> resources = businessArchive.getResources("^" + folder + "/.*$"); for (Map.Entry<String, byte[]> entry : resources.entrySet()) { processResourcesService.add(processDefinition.getId(), entry.getKey().substring((folder + "/").length()), type, entry.getValue()); } }
void saveResources(BusinessArchive businessArchive, SProcessDefinition processDefinition, String folder, BARResourceType type) throws SRecorderException { final Map<String, byte[]> resources = businessArchive.getResources("^" + folder + "/.*$"); for (Map.Entry<String, byte[]> entry : resources.entrySet()) { processResourcesService.add(processDefinition.getId(), entry.getKey().substring((folder + "/").length()), type, entry.getValue()); } }
@Override public void saveToBarFolder(final BusinessArchive businessArchive, final File barFolder) throws IOException { final Map<String, byte[]> resources = businessArchive.getResources(getFileName()); for (final Entry<String, byte[]> entry : resources.entrySet()) { final byte[] value = entry.getValue(); if (value != null) { final File file = new File(barFolder, entry.getKey()); IOUtil.write(file, entry.getValue()); } } }
@Override public void saveToBarFolder(final BusinessArchive businessArchive, final File barFolder) throws IOException { final Map<String, byte[]> resources = businessArchive.getResources(getFileName()); for (final Entry<String, byte[]> entry : resources.entrySet()) { final byte[] value = entry.getValue(); if (value != null) { final File file = new File(barFolder, entry.getKey()); IOUtil.write(file, entry.getValue()); } } }
@Override public boolean deploy(final BusinessArchive businessArchive, final SProcessDefinition processDefinition) throws ConnectorException, SBonitaException { final Map<String, byte[]> resources = businessArchive.getResources("^classpath/.*$"); // remove the classpath/ on path of dependencies final Map<String, byte[]> resourcesWithRealName = new HashMap<>(resources.size()); for (final Map.Entry<String, byte[]> resource : resources.entrySet()) { final String name = resource.getKey().substring(10); final byte[] jarContent = resource.getValue(); resourcesWithRealName.put(name, jarContent); } addDependencies(resourcesWithRealName, dependencyService, processDefinition.getId()); return true; }
@Override public boolean deploy(final BusinessArchive businessArchive, final SProcessDefinition processDefinition) throws ConnectorException, SBonitaException { final Map<String, byte[]> resources = businessArchive.getResources("^classpath/.*$"); // remove the classpath/ on path of dependencies final Map<String, byte[]> resourcesWithRealName = new HashMap<>(resources.size()); for (final Map.Entry<String, byte[]> resource : resources.entrySet()) { final String name = resource.getKey().substring(10); final byte[] jarContent = resource.getValue(); resourcesWithRealName.put(name, jarContent); } addDependencies(resourcesWithRealName, dependencyService, processDefinition.getId()); return true; }
/** * Retrieves a {@link java.util.Map} representing the resources having paths matching with the given regular expression. The {@code Map} keys store the * resource paths and the {@code Map} values store the resource content. * <br> * <p>Example:</p> * * <pre> * businessArchive.getResources("^classpath/.*$") * </pre> * * <br> * * @param regex the regular expression used to match the resource path * @return a {@link java.util.Map} representing the resources having paths matching with the given regular expression */ public Map<String, byte[]> getResources(final String regex) { final Pattern pattern = Pattern.compile(regex); final Map<String, byte[]> result = new HashMap<>(); for (final Entry<String, byte[]> resource : getResources().entrySet()) { if (pattern.matcher(resource.getKey()).matches()) { result.put(resource.getKey(), resource.getValue()); } } return result; }
@Override public void saveToBarFolder(final BusinessArchive businessArchive, final File barFolder) throws IOException { final File folder = new File(barFolder, getFolderName()); folder.mkdir(); final int beginIndex = getFolderName().length(); final Map<String, byte[]> resources = businessArchive.getResources("^" + getFolderName() + "/.*$"); for (final Entry<String, byte[]> entry : resources.entrySet()) { final File file = new File(folder, entry.getKey().substring(beginIndex)); IOUtil.write(file, entry.getValue()); } }
@Override public void saveToBarFolder(final BusinessArchive businessArchive, final File barFolder) throws IOException { final File folder = new File(barFolder, getFolderName()); folder.mkdir(); final int beginIndex = getFolderName().length(); final Map<String, byte[]> resources = businessArchive.getResources("^" + getFolderName() + "/.*$"); for (final Entry<String, byte[]> entry : resources.entrySet()) { final File file = new File(folder, entry.getKey().substring(beginIndex)); IOUtil.write(file, entry.getValue()); } }
@Override public boolean deploy(final BusinessArchive businessArchive, final SProcessDefinition processDefinition) throws ConnectorException, SRecorderException { try { final Map<String, byte[]> resources = businessArchive.getResources("^" + CONNECTOR + "/.*$"); for (Map.Entry<String, byte[]> entry : resources.entrySet()) { connectorService.addConnectorImplementation(processDefinition.getId(), entry.getKey().substring((CONNECTOR + "/").length()), entry.getValue()); } return connectorService.loadConnectors(processDefinition) && checkAllConnectorsHaveImplementation(connectorService, processDefinition).isEmpty(); } catch (final SConnectorException e) { throw new ConnectorException(e); } }
@Override public boolean deploy(final BusinessArchive businessArchive, final SProcessDefinition processDefinition) throws ConnectorException, SRecorderException { try { final Map<String, byte[]> resources = businessArchive.getResources("^" + CONNECTOR + "/.*$"); for (Map.Entry<String, byte[]> entry : resources.entrySet()) { connectorService.addConnectorImplementation(processDefinition.getId(), entry.getKey().substring((CONNECTOR + "/").length()), entry.getValue()); } return connectorService.loadConnectors(processDefinition) && checkAllConnectorsHaveImplementation(connectorService, processDefinition).isEmpty(); } catch (final SConnectorException e) { throw new ConnectorException(e); } }
@Override public Map<String, byte[]> getProcessResources(final long processDefinitionId, final String filenamesPattern) throws RetrieveException { try { BusinessArchive businessArchive = getTenantAccessor().getBusinessArchiveService().export(processDefinitionId); return businessArchive.getResources(filenamesPattern); } catch (SBonitaException | InvalidBusinessArchiveFormatException e) { throw new RetrieveException(e); } }
@Override public Map<String, byte[]> getProcessResources(final long processDefinitionId, final String filenamesPattern) throws RetrieveException { try { BusinessArchive businessArchive = getTenantAccessor().getBusinessArchiveService().export(processDefinitionId); return businessArchive.getResources(filenamesPattern); } catch (SBonitaException | InvalidBusinessArchiveFormatException e) { throw new RetrieveException(e); } }
@Test public void manageBusinessArchiveResources() throws Exception { final ProcessDefinitionBuilder processDefinitionBuilder = new ProcessDefinitionBuilder().createNewInstance("MyProcess", "1.0"); final BusinessArchive businessArchive = new BusinessArchiveBuilder().createNewBusinessArchive().setProcessDefinition(processDefinitionBuilder.done()) .addExternalResource(new BarResource("dummy.txt", new byte[] { 'a', 'b', 'c', 'd' })).done(); // Add a resource to the biz archive: BusinessArchiveFactory.writeBusinessArchiveToFile(businessArchive, barFile); // read from the file final BusinessArchive readBusinessArchive = BusinessArchiveFactory.readBusinessArchive(barFile); assertTrue("Added resource not found in BusinessArchive", readBusinessArchive.getResources().containsKey("resources/dummy.txt")); }