@Override public byte[] getPageContent(final long pageId) throws SBonitaReadException, SObjectNotFoundException { final SPageWithContent page = persistenceService.selectById(new ReadOnlySelectByIdDescriptor<>(SPageWithContent.class, pageId)); if (page == null) { throw new SObjectNotFoundException("Page with id " + pageId + " not found"); } final byte[] content = page.getContent(); try { final Map<String, byte[]> contentAsMap = unzip(content); final byte[] bytes = contentAsMap.get("page.properties"); final Properties pageProperties = new Properties(); if (bytes != null) { pageProperties.load(new ByteArrayInputStream(bytes)); } pageProperties.put(PROPERTIES_NAME, page.getName()); pageProperties.put(PROPERTIES_DISPLAY_NAME, page.getDisplayName()); pageProperties.put(PROPERTIES_DESCRIPTION, page.getDescription()); contentAsMap.put("page.properties", IOUtil.getPropertyAsString(pageProperties, "The name must start with 'custompage_'")); return IOUtil.zip(contentAsMap); } catch (final IOException e) { throw new SBonitaReadException("the page is not a valid zip file", e); } }
@Override public byte[] getPageContent(final long pageId) throws SBonitaReadException, SObjectNotFoundException { final SPageWithContent page = persistenceService.selectById(new ReadOnlySelectByIdDescriptor<>(SPageWithContent.class, pageId)); if (page == null) { throw new SObjectNotFoundException("Page with id " + pageId + " not found"); } final byte[] content = page.getContent(); try { final Map<String, byte[]> contentAsMap = unzip(content); final byte[] bytes = contentAsMap.get("page.properties"); final Properties pageProperties = new Properties(); if (bytes != null) { pageProperties.load(new ByteArrayInputStream(bytes)); } pageProperties.put(PROPERTIES_NAME, page.getName()); pageProperties.put(PROPERTIES_DISPLAY_NAME, page.getDisplayName()); pageProperties.put(PROPERTIES_DESCRIPTION, page.getDescription()); contentAsMap.put("page.properties", IOUtil.getPropertyAsString(pageProperties, "The name must start with 'custompage_'")); return IOUtil.zip(contentAsMap); } catch (final IOException e) { throw new SBonitaReadException("the page is not a valid zip file", e); } }
Properties readPageZip(final byte[] content, final boolean provided) throws SInvalidPageZipMissingIndexException, SInvalidPageZipMissingAPropertyException, SInvalidPageZipInconsistentException, SInvalidPageZipMissingPropertiesException, SInvalidPageTokenException { final Properties pageProperties; if (content == null) { throw new SInvalidPageZipInconsistentException("Content can't be null"); } try { final Map<String, byte[]> zipContent = unzip(content); pageProperties = helper.loadPageProperties(zipContent); if (isAnAPIExtension(pageProperties)) { checkApiControllerExists(zipContent, pageProperties); } else { checkZipContainsRequiredEntries(zipContent); } checkPageNameIsValid(pageProperties.getProperty(PageService.PROPERTIES_NAME), provided); checkPageDisplayNameIsValid(pageProperties.getProperty(PageService.PROPERTIES_DISPLAY_NAME)); } catch (final IOException e) { throw new SInvalidPageZipInconsistentException("Error while reading zip file", e); } return pageProperties; }
Properties readPageZip(final byte[] content, final boolean provided) throws SInvalidPageZipMissingIndexException, SInvalidPageZipMissingAPropertyException, SInvalidPageZipInconsistentException, SInvalidPageZipMissingPropertiesException, SInvalidPageTokenException { final Properties pageProperties; if (content == null) { throw new SInvalidPageZipInconsistentException("Content can't be null"); } try { final Map<String, byte[]> zipContent = unzip(content); pageProperties = helper.loadPageProperties(zipContent); if (isAnAPIExtension(pageProperties)) { checkApiControllerExists(zipContent, pageProperties); } else { checkZipContainsRequiredEntries(zipContent); } checkPageNameIsValid(pageProperties.getProperty(PageService.PROPERTIES_NAME), provided); checkPageDisplayNameIsValid(pageProperties.getProperty(PageService.PROPERTIES_DISPLAY_NAME)); } catch (final IOException e) { throw new SInvalidPageZipInconsistentException("Error while reading zip file", e); } return pageProperties; }
@Override public SPage addPage(final SPage page, final byte[] content) throws SObjectCreationException, SObjectAlreadyExistsException, SInvalidPageZipException, SInvalidPageTokenException { try { checkZipContainsRequiredEntries(unzip(content)); checkPageNameIsValid(page.getName(), page.isProvided()); checkPageDisplayNameIsValid(page.getDisplayName()); return insertPage(page, content); } catch (final IOException e) { throw new SInvalidPageZipInconsistentException("Error while reading zip file", e); } }
@Override public SPage addPage(final SPage page, final byte[] content) throws SObjectCreationException, SObjectAlreadyExistsException, SInvalidPageZipException, SInvalidPageTokenException { try { checkZipContainsRequiredEntries(unzip(content)); checkPageNameIsValid(page.getName(), page.isProvided()); checkPageDisplayNameIsValid(page.getDisplayName()); return insertPage(page, content); } catch (final IOException e) { throw new SInvalidPageZipInconsistentException("Error while reading zip file", e); } }