void checkVersion(final String content) throws InvalidBusinessArchiveFormatException { final Pattern pattern = Pattern.compile("http://www\\.bonitasoft\\.org/ns/process/client/(\\d\\.\\d)"); final Matcher matcher = pattern.matcher(content); final boolean find = matcher.find(); if (!find) { throw new InvalidBusinessArchiveFormatException("There is no bonitasoft process namespace declaration"); } final String group = matcher.group(1); if (!group.equals("7.4")) { throw new InvalidBusinessArchiveFormatException("Wrong version of your process definition, " + group + " namespace is not compatible with your current version. Use the studio to update it."); } }
public InvalidBusinessArchiveFormatException(final List<String> messages) { super(constructMessage(messages)); }
@Override public ProcessDefinition deployAndEnableProcess(final DesignProcessDefinition designProcessDefinition) throws ProcessDeployException, ProcessEnablementException, AlreadyExistsException, InvalidProcessDefinitionException { BusinessArchive businessArchive; try { businessArchive = new BusinessArchiveBuilder().createNewBusinessArchive().setProcessDefinition(designProcessDefinition).done(); } catch (final InvalidBusinessArchiveFormatException e) { throw new InvalidProcessDefinitionException(e.getMessage()); } return deployAndEnableProcess(businessArchive); }
@Override public ProcessDefinition deployAndEnableProcess(final DesignProcessDefinition designProcessDefinition) throws ProcessDeployException, ProcessEnablementException, AlreadyExistsException, InvalidProcessDefinitionException { BusinessArchive businessArchive; try { businessArchive = new BusinessArchiveBuilder().createNewBusinessArchive().setProcessDefinition(designProcessDefinition).done(); } catch (final InvalidBusinessArchiveFormatException e) { throw new InvalidProcessDefinitionException(e.getMessage()); } return deployAndEnableProcess(businessArchive); }
void checkVersion(final String content) throws InvalidBusinessArchiveFormatException { final Pattern pattern = Pattern.compile("http://www\\.bonitasoft\\.org/ns/process/client/(\\d\\.\\d)"); final Matcher matcher = pattern.matcher(content); final boolean find = matcher.find(); if (!find) { throw new InvalidBusinessArchiveFormatException("There is no bonitasoft process namespace declaration"); } final String group = matcher.group(1); if (!group.equals("7.4")) { throw new InvalidBusinessArchiveFormatException("Wrong version of your process definition, " + group + " namespace is not compatible with your current version. Use the studio to update it."); } }
public InvalidBusinessArchiveFormatException(final List<String> messages) { super(constructMessage(messages)); }
protected void checkProcessInfos(final File barFolder, final DesignProcessDefinition processDefinition) throws InvalidBusinessArchiveFormatException { final String processInfos = getProcessInfos(generateInfosFromDefinition(processDefinition)); String fileContent; try { fileContent = IOUtil.read(new File(barFolder, PROCESS_INFOS_FILE)); if (!processInfos.equals(fileContent.trim())) { throw new InvalidBusinessArchiveFormatException("Invalid Business Archive format"); } } catch (final IOException e) { throw new InvalidBusinessArchiveFormatException("Invalid Business Archive format"); } }
protected void checkProcessInfos(final File barFolder, final DesignProcessDefinition processDefinition) throws InvalidBusinessArchiveFormatException { final String processInfos = getProcessInfos(generateInfosFromDefinition(processDefinition)); String fileContent; try { fileContent = IOUtil.read(new File(barFolder, PROCESS_INFOS_FILE)); if (!processInfos.equals(fileContent.trim())) { throw new InvalidBusinessArchiveFormatException("Invalid Business Archive format"); } } catch (final IOException e) { throw new InvalidBusinessArchiveFormatException("Invalid Business Archive format"); } }
protected BusinessArchive readBusinessArchive(final InputStream inputStream, List<BusinessArchiveContribution> contributions) throws IOException, InvalidBusinessArchiveFormatException { File barFolder = File.createTempFile("tempBarFolder", null); barFolder.delete(); barFolder.mkdir(); try { IOUtil.unzipToFolder(inputStream, barFolder); return getBusinessArchive(barFolder, contributions); } catch (final InvalidBusinessArchiveFormatException e) { throw e; } catch (final Exception e) { throw new InvalidBusinessArchiveFormatException("Invalid format, can't read the BAR file", e); } finally { IOUtil.deleteDir(barFolder); } }
protected BusinessArchive readBusinessArchive(final InputStream inputStream, List<BusinessArchiveContribution> contributions) throws IOException, InvalidBusinessArchiveFormatException { File barFolder = File.createTempFile("tempBarFolder", null); barFolder.delete(); barFolder.mkdir(); try { IOUtil.unzipToFolder(inputStream, barFolder); return getBusinessArchive(barFolder, contributions); } catch (final InvalidBusinessArchiveFormatException e) { throw e; } catch (final Exception e) { throw new InvalidBusinessArchiveFormatException("Invalid format, can't read the BAR file", e); } finally { IOUtil.deleteDir(barFolder); } }
public DesignProcessDefinition deserializeProcessDefinition(final File file) throws IOException, InvalidBusinessArchiveFormatException { String content = IOUtil.read(file); try { return convertXmlToProcess(content); } catch (final IOException e) { checkVersion(content); throw new InvalidBusinessArchiveFormatException(e); } }
public DesignProcessDefinition deserializeProcessDefinition(final File file) throws IOException, InvalidBusinessArchiveFormatException { String content = IOUtil.read(file); try { return convertXmlToProcess(content); } catch (final IOException e) { checkVersion(content); throw new InvalidBusinessArchiveFormatException(e); } }
private BusinessArchive getBusinessArchive(final File barFolder, List<BusinessArchiveContribution> contributions) throws IOException, InvalidBusinessArchiveFormatException { final BusinessArchive businessArchive = new BusinessArchive(); for (final BusinessArchiveContribution contribution : contributions) { if (!contribution.readFromBarFolder(businessArchive, barFolder) && contribution.isMandatory()) { throw new InvalidBusinessArchiveFormatException("Invalid format, can't read '" + contribution.getName() + "' from the BAR file"); } } return businessArchive; }
private BusinessArchive getBusinessArchive(final File barFolder, List<BusinessArchiveContribution> contributions) throws IOException, InvalidBusinessArchiveFormatException { final BusinessArchive businessArchive = new BusinessArchive(); for (final BusinessArchiveContribution contribution : contributions) { if (!contribution.readFromBarFolder(businessArchive, barFolder) && contribution.isMandatory()) { throw new InvalidBusinessArchiveFormatException("Invalid format, can't read '" + contribution.getName() + "' from the BAR file"); } } return businessArchive; }
/** * @return * The BusinessArchive * @throws InvalidBusinessArchiveFormatException * when the business archive is inconsistent in the current state */ public BusinessArchive done() throws InvalidBusinessArchiveFormatException { if (entity.getProcessDefinition() == null) { throw new InvalidBusinessArchiveFormatException("missing process definition"); } final ArrayList<String> errors = new ArrayList<>(); for (final DocumentDefinition document : entity.getProcessDefinition().getProcessContainer().getDocumentDefinitions()) { if (document.getFile() != null && !document.getFile().isEmpty()) { final byte[] resources = entity.getResource("documents/" + document.getFile()); if (resources == null) { errors.add("missing document in the business archive that is present in the process definition " + document.getFile()); } } } if (!errors.isEmpty()) { throw new InvalidBusinessArchiveFormatException(errors); } return entity; }
/** * @return * The BusinessArchive * @throws InvalidBusinessArchiveFormatException * when the business archive is inconsistent in the current state */ public BusinessArchive done() throws InvalidBusinessArchiveFormatException { if (entity.getProcessDefinition() == null) { throw new InvalidBusinessArchiveFormatException("missing process definition"); } final ArrayList<String> errors = new ArrayList<>(); for (final DocumentDefinition document : entity.getProcessDefinition().getProcessContainer().getDocumentDefinitions()) { if (document.getFile() != null && !document.getFile().isEmpty()) { final byte[] resources = entity.getResource("documents/" + document.getFile()); if (resources == null) { errors.add("missing document in the business archive that is present in the process definition " + document.getFile()); } } } if (!errors.isEmpty()) { throw new InvalidBusinessArchiveFormatException(errors); } return entity; }