public SPage constructSPage(final PageCreator pageCreator, final long creatorUserId) { final Map<PageCreator.PageField, Serializable> fields = pageCreator.getFields(); final String name = (String) fields.get(PageCreator.PageField.NAME); final String description = (String) fields.get(PageCreator.PageField.DESCRIPTION); final String displayName = (String) fields.get(PageCreator.PageField.DISPLAY_NAME); final String contentName = (String) fields.get(PageCreator.PageField.CONTENT_NAME); final String contentType = (String) fields.get(PageCreator.PageField.CONTENT_TYPE); final Long processDefinitionId = (Long) fields.get(PageCreator.PageField.PROCESS_DEFINITION_ID); Boolean hidden = (Boolean) fields.get(PageCreator.PageField.HIDDEN); if (hidden == null) { hidden = false; } return buildSPage(creatorUserId, name, description, displayName, contentName, contentType, processDefinitionId, hidden); }
public PageCreator(String name, String zipName, String contentType, Long processDefinitionId) { this(name, zipName); setContentType(contentType); setProcessDefinitionId(processDefinitionId); }
@Test public void should_create_page_with_process_definition() { // given final PageCreator pageCreator = new PageCreator(NAME, ZIP_FILE_NAME).setDisplayName(DISPLAY_NAME).setDescription(DESCRIPTION) .setProcessDefinitionId(PROCESS_DEFINITION_ID).setContentType(ContentType.FORM); // when final Map<PageField, Serializable> fields = pageCreator.getFields(); // then assertThat(fields).as("should set content type").containsOnly(entry(PageField.NAME, NAME), entry(PageField.DISPLAY_NAME, DISPLAY_NAME), entry(PageField.DESCRIPTION, DESCRIPTION), entry(PageField.CONTENT_TYPE, ContentType.PAGE), entry(PageField.CONTENT_NAME, ZIP_FILE_NAME), entry(PageField.CONTENT_TYPE, ContentType.FORM), entry(PageField.PROCESS_DEFINITION_ID, PROCESS_DEFINITION_ID) ); assertThat(pageCreator.getName()).isEqualTo(NAME); }
@Test public void should_create_page_with_default_content_type() { // given final PageCreator pageCreator = new PageCreator(NAME, ZIP_FILE_NAME).setDisplayName(DISPLAY_NAME).setDescription(DESCRIPTION); // when final Map<PageField, Serializable> fields = pageCreator.getFields(); // then assertThat(fields).as("should set content type").containsOnly(entry(PageField.NAME, NAME), entry(PageField.DISPLAY_NAME, DISPLAY_NAME), entry(PageField.DESCRIPTION, DESCRIPTION), entry(PageField.CONTENT_TYPE, ContentType.PAGE), entry(PageField.CONTENT_NAME, ZIP_FILE_NAME) ); assertThat(pageCreator.getName()).isEqualTo(NAME); }
@Test public void should_print_all_fields() { // given final PageCreator pageCreator = new PageCreator(NAME, ZIP_FILE_NAME, ContentType.FORM, 12345L).setDisplayName(DISPLAY_NAME).setDescription( DESCRIPTION); // when final Map<PageField, Serializable> fields = pageCreator.getFields(); // then assertThat(pageCreator.toString()).as("should print human readable to string").isEqualTo("PageCreator [fields=" + fields + "]"); } }
private void deployPage(String resourcePath, byte[] pageContent, Long processDefinitionId, long userId, PageService pageService) throws SBonitaException { final Matcher pathMatcher = getPathMatcher(resourcePath); if (pathMatcher.matches()) { final String pageName = pathMatcher.group(1); final String extension = pathMatcher.group(2); String contentName = pageName + "." + extension; final SPage sPage = pageService.getPageByNameAndProcessDefinitionId(pageName, processDefinitionId); if (sPage != null) { pageService.updatePageContent(sPage.getId(), pageContent, contentName); } else { final Properties pageProperties = pageService.readPageZip(pageContent); final PageCreator pageCreator = new PageCreator(pageName, contentName, ContentType.FORM, processDefinitionId) .setDisplayName(pageProperties.getProperty(PageService.PROPERTIES_DISPLAY_NAME)) .setDescription(pageProperties.getProperty(PageService.PROPERTIES_DESCRIPTION)); final SPage newPage = new PageModelConverter().constructSPage(pageCreator, userId); pageService.addPage(newPage, pageContent); } } }
@Test public void should_create_page_with_form_content_type() { // given final PageCreator pageCreator = new PageCreator(NAME, ZIP_FILE_NAME, ContentType.FORM, 12345L).setDisplayName(DISPLAY_NAME); // when final Map<PageField, Serializable> fields = pageCreator.getFields(); // then assertThat(fields).as("should set content type").containsOnly( entry(PageField.NAME, NAME), entry(PageField.DISPLAY_NAME, DISPLAY_NAME), entry(PageField.CONTENT_TYPE, ContentType.FORM), entry(PageField.PROCESS_DEFINITION_ID, 12345L), entry(PageField.CONTENT_NAME, ZIP_FILE_NAME) ); }
public PageCreator(final String name, final String zipName) { fields = new HashMap<>(); fields.put(PageField.NAME, name); fields.put(PageField.CONTENT_NAME, zipName); setContentType(ContentType.PAGE); }
public Page createPage(final PageCreator pageCreator, final byte[] content) throws AlreadyExistsException, CreationException, InvalidPageTokenException, InvalidPageZipContentException { final SPage sPage = constructPage(pageCreator, userIdFromSession); try { final SPage addPage = pageService.addPage(sPage, content); return convertToPage(addPage); } catch (final SObjectAlreadyExistsException e) { throw new AlreadyExistsException("A page already exists with the name " + pageCreator.getName()); } catch (final SInvalidPageTokenException e) { throw new InvalidPageTokenException(e.getMessage(), e); } catch (final SInvalidPageZipException e) { throw convertException(e); } catch (final SBonitaException e) { throw new CreationException(e); } }
private void deployPage(String resourcePath, byte[] pageContent, Long processDefinitionId, long userId, PageService pageService) throws SBonitaException { final Matcher pathMatcher = getPathMatcher(resourcePath); if (pathMatcher.matches()) { final String pageName = pathMatcher.group(1); final String extension = pathMatcher.group(2); String contentName = pageName + "." + extension; final SPage sPage = pageService.getPageByNameAndProcessDefinitionId(pageName, processDefinitionId); if (sPage != null) { pageService.updatePageContent(sPage.getId(), pageContent, contentName); } else { final Properties pageProperties = pageService.readPageZip(pageContent); final PageCreator pageCreator = new PageCreator(pageName, contentName, ContentType.FORM, processDefinitionId) .setDisplayName(pageProperties.getProperty(PageService.PROPERTIES_DISPLAY_NAME)) .setDescription(pageProperties.getProperty(PageService.PROPERTIES_DESCRIPTION)); final SPage newPage = new PageModelConverter().constructSPage(pageCreator, userId); pageService.addPage(newPage, pageContent); } } }
public PageCreator(final String name, final String zipName) { fields = new HashMap<>(); fields.put(PageField.NAME, name); fields.put(PageField.CONTENT_NAME, zipName); setContentType(ContentType.PAGE); }
public Page createPage(final PageCreator pageCreator, final byte[] content) throws AlreadyExistsException, CreationException, InvalidPageTokenException, InvalidPageZipContentException { final SPage sPage = constructPage(pageCreator, userIdFromSession); try { final SPage addPage = pageService.addPage(sPage, content); return convertToPage(addPage); } catch (final SObjectAlreadyExistsException e) { throw new AlreadyExistsException("A page already exists with the name " + pageCreator.getName()); } catch (final SInvalidPageTokenException e) { throw new InvalidPageTokenException(e.getMessage(), e); } catch (final SInvalidPageZipException e) { throw convertException(e); } catch (final SBonitaException e) { throw new CreationException(e); } }
public PageCreator(String name, String zipName, String contentType, Long processDefinitionId) { this(name, zipName); setContentType(contentType); setProcessDefinitionId(processDefinitionId); }
public SPage constructSPage(final PageCreator pageCreator, final long creatorUserId) { final Map<PageCreator.PageField, Serializable> fields = pageCreator.getFields(); final String name = (String) fields.get(PageCreator.PageField.NAME); final String description = (String) fields.get(PageCreator.PageField.DESCRIPTION); final String displayName = (String) fields.get(PageCreator.PageField.DISPLAY_NAME); final String contentName = (String) fields.get(PageCreator.PageField.CONTENT_NAME); final String contentType = (String) fields.get(PageCreator.PageField.CONTENT_TYPE); final Long processDefinitionId = (Long) fields.get(PageCreator.PageField.PROCESS_DEFINITION_ID); Boolean hidden = (Boolean) fields.get(PageCreator.PageField.HIDDEN); if (hidden == null) { hidden = false; } return buildSPage(creatorUserId, name, description, displayName, contentName, contentType, processDefinitionId, hidden); }