public Page toPage(final SPage sPage) { Long processDefinitionId = sPage.getProcessDefinitionId() > 0 ? sPage.getProcessDefinitionId() : null; return new PageImpl(sPage.getId(), sPage.getName(), sPage.getDisplayName(), sPage.isProvided(), sPage.isHidden(), sPage.getDescription(), sPage.getInstallationDate(), sPage.getInstalledBy(), sPage.getLastModificationDate(), sPage.getLastUpdatedBy(), sPage.getContentName(), sPage.getContentType(), processDefinitionId); }
private SPage checkIfPageAlreadyExists(final SPage page) throws SBonitaReadException { SPage existingPage; if (page.getProcessDefinitionId() > 0) { existingPage = getPageByNameAndProcessDefinitionId(page.getName(), page.getProcessDefinitionId()); } else { existingPage = getPageByName(page.getName()); } return existingPage; }
@Override public void pageDeleted(final SPage page) throws SBonitaReadException, SDeletionException { if (SContentType.API_EXTENSION.equals(page.getContentType())) { List<SPageMapping> mappings; do { mappings = pageMappingService.get(page.getId(), 0, MAX_RESULTS); for (final SPageMapping mapping : mappings) { pageMappingService.delete(mapping); } } while (mappings.size() == MAX_RESULTS); } }
switch (field.getKey()) { case NAME: pageUpdateBuilder.updateName(sPage.getName()); break; case DISPLAY_NAME: pageUpdateBuilder.updateDisplayName(sPage.getDisplayName()); break; case DESCRIPTION: pageUpdateBuilder.updateDescription(sPage.getDescription()); break; case CONTENT_NAME: pageUpdateBuilder.updateContentName(sPage.getContentName()); break; case CONTENT_TYPE: pageUpdateBuilder.updateContentType(sPage.getContentType()); break; case PROCESS_DEFINITION_ID: pageUpdateBuilder.updateProcessDefinitionId(sPage.getProcessDefinitionId()); break; default:
private void addPageMapping(final SPage page, final Properties apiProperties) throws SObjectCreationException, IOException, SInvalidPageZipMissingPropertiesException { final List<String> mappings = getKeysOfPageMappings(apiProperties); for (final String mapping : mappings) { pageMappingService.create(mapping, page.getId(), Collections.<String> emptyList()); } }
protected void checkPageDuplicate(final SPage sPage, final EntityUpdateDescriptor entityUpdateDescriptor, final SPageLogBuilder logBuilder, final String logMethodName) throws SBonitaReadException, SObjectAlreadyExistsException { if (entityUpdateDescriptor.getFields().containsKey(SPageFields.PAGE_NAME) || entityUpdateDescriptor.getFields().containsKey(SPageFields.PAGE_PROCESS_DEFINITION_ID)) { String sPageName = sPage.getName(); long sPageProcessDefinitionId = sPage.getProcessDefinitionId(); if (entityUpdateDescriptor.getFields().containsKey(SPageFields.PAGE_NAME)) { sPageName = entityUpdateDescriptor.getFields().get(SPageFields.PAGE_NAME).toString(); } if (entityUpdateDescriptor.getFields().containsKey(SPageFields.PAGE_PROCESS_DEFINITION_ID)) { sPageProcessDefinitionId = Long.parseLong(entityUpdateDescriptor.getFields().get(SPageFields.PAGE_PROCESS_DEFINITION_ID).toString()); } final SPage page; if (sPageProcessDefinitionId > 0) { page = getPageByNameAndProcessDefinitionId(sPageName, sPageProcessDefinitionId); } else { page = getPageByName(sPageName); } if (null != page && page.getId() != sPage.getId()) { initiateLogBuilder(sPage.getId(), SQueriableLog.STATUS_FAIL, logBuilder, logMethodName); throwAlreadyExistsException(page.getName()); } } }
@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); } }
SPage insertPage(final SPage page, final byte[] content) throws SObjectAlreadyExistsException, SObjectCreationException { final SPageLogBuilder logBuilder = getPageLog(ActionType.CREATED, "Adding a new page with name " + page.getName()); try { final SPageWithContent pageContent = new SPageWithContentImpl(page, content); final SPage pageByName = checkIfPageAlreadyExists(page); if (null != pageByName) { initiateLogBuilder(page.getId(), SQueriableLog.STATUS_FAIL, logBuilder, METHOD_NAME_ADD_PAGE); throwAlreadyExistsException(pageByName.getName()); } recorder.recordInsert(new InsertRecord(pageContent), PAGE); page.setId(pageContent.getId()); notifyPageInsert(page, content); return page; } catch (final SObjectCreationException ce) { throw ce; } catch (SRecorderException | SBonitaReadException re) { throw new SObjectCreationException(re); } }
private void deleteProfileEntry(final SPage sPage) throws SBonitaReadException, SProfileEntryNotFoundException, SProfileEntryDeletionException { final List<OrderByOption> orderByOptions = Collections .singletonList(new OrderByOption(SProfileEntry.class, SProfileEntryBuilderFactory.INDEX, OrderByType.ASC)); final List<FilterOption> filters = new ArrayList<>(); filters.add(new FilterOption(SProfileEntry.class, SProfileEntryBuilderFactory.PAGE, sPage.getName())); filters.add(new FilterOption(SProfileEntry.class, SProfileEntryBuilderFactory.CUSTOM, new Boolean(true))); final QueryOptions queryOptions = new QueryOptions(0, QueryOptions.UNLIMITED_NUMBER_OF_RESULTS, orderByOptions, filters, null); final List<SProfileEntry> searchProfileEntries = profileService.searchProfileEntries(queryOptions); for (final SProfileEntry sProfileEntry : searchProfileEntries) { profileService.deleteProfileEntry(sProfileEntry.getId()); if (sProfileEntry.getParentId() > 0) { deleteParentIfNoMoreChildren(sProfileEntry); } } }
private void deletePage(final SPage sPage) throws SObjectModificationException { final SPageLogBuilder logBuilder = getPageLog(ActionType.DELETED, "Deleting page named: " + sPage.getName()); try { deleteProfileEntry(sPage); for (final PageServiceListener pageServiceListener : pageServiceListeners) { pageServiceListener.pageDeleted(sPage); } recorder.recordDelete(new DeleteRecord(sPage), PAGE); initiateLogBuilder(sPage.getId(), SQueriableLog.STATUS_OK, logBuilder, METHOD_DELETE_PAGE); } catch (SRecorderException | SBonitaReadException | SProfileEntryNotFoundException | SProfileEntryDeletionException | SDeletionException re) { initiateLogBuilder(sPage.getId(), SQueriableLog.STATUS_FAIL, logBuilder, METHOD_DELETE_PAGE); throw new SObjectModificationException(re); } }
@Override public void pageInserted(final SPage sPage, final byte[] content) throws SObjectCreationException { if (SContentType.API_EXTENSION.equals(sPage.getContentType())){ try { addPageMapping(sPage, helper.loadPageProperties(content)); } catch (final IOException | SInvalidPageZipMissingPropertiesException e) { throw new SObjectCreationException(e); } } }
public void updatePageContent(final long pageId, final byte[] content) throws UpdateException, UpdatingWithInvalidPageTokenException, UpdatingWithInvalidPageZipContentException { final SPageUpdateBuilder pageUpdateBuilder = getPageUpdateBuilder(); pageUpdateBuilder.updateLastModificationDate(System.currentTimeMillis()); pageUpdateBuilder.updateLastUpdatedBy(userIdFromSession); try { final SPage page = pageService.getPage(pageId); pageService.updatePageContent(pageId, content, page.getContentName()); pageService.updatePage(pageId, pageUpdateBuilder.done()); } catch (final SInvalidPageTokenException e) { throw new UpdatingWithInvalidPageTokenException(e.getMessage(), e); } catch (final SInvalidPageZipException e) { throw new UpdatingWithInvalidPageZipContentException(e.getMessage(), e); } catch (final SBonitaException sBonitaException) { throw new UpdateException(sBonitaException); } }
switch (field.getKey()) { case NAME: pageUpdateBuilder.updateName(sPage.getName()); break; case DISPLAY_NAME: pageUpdateBuilder.updateDisplayName(sPage.getDisplayName()); break; case DESCRIPTION: pageUpdateBuilder.updateDescription(sPage.getDescription()); break; case CONTENT_NAME: pageUpdateBuilder.updateContentName(sPage.getContentName()); break; case CONTENT_TYPE: pageUpdateBuilder.updateContentType(sPage.getContentType()); break; case PROCESS_DEFINITION_ID: pageUpdateBuilder.updateProcessDefinitionId(sPage.getProcessDefinitionId()); break; default:
private void deleteProcessPages(Long processDefinitionId) throws SBonitaReadException, SObjectModificationException, SObjectNotFoundException { List<SPage> sPages; do { sPages = pageService.getPageByProcessDefinitionId(processDefinitionId, 0, NUMBER_OF_RESULTS); for (SPage sPage : sPages) { pageService.deletePage(sPage.getId()); } } while (sPages.size() == NUMBER_OF_RESULTS); }
protected void checkPageDuplicate(final SPage sPage, final EntityUpdateDescriptor entityUpdateDescriptor, final SPageLogBuilder logBuilder, final String logMethodName) throws SBonitaReadException, SObjectAlreadyExistsException { if (entityUpdateDescriptor.getFields().containsKey(SPageFields.PAGE_NAME) || entityUpdateDescriptor.getFields().containsKey(SPageFields.PAGE_PROCESS_DEFINITION_ID)) { String sPageName = sPage.getName(); long sPageProcessDefinitionId = sPage.getProcessDefinitionId(); if (entityUpdateDescriptor.getFields().containsKey(SPageFields.PAGE_NAME)) { sPageName = entityUpdateDescriptor.getFields().get(SPageFields.PAGE_NAME).toString(); } if (entityUpdateDescriptor.getFields().containsKey(SPageFields.PAGE_PROCESS_DEFINITION_ID)) { sPageProcessDefinitionId = Long.parseLong(entityUpdateDescriptor.getFields().get(SPageFields.PAGE_PROCESS_DEFINITION_ID).toString()); } final SPage page; if (sPageProcessDefinitionId > 0) { page = getPageByNameAndProcessDefinitionId(sPageName, sPageProcessDefinitionId); } else { page = getPageByName(sPageName); } if (null != page && page.getId() != sPage.getId()) { initiateLogBuilder(sPage.getId(), SQueriableLog.STATUS_FAIL, logBuilder, logMethodName); throwAlreadyExistsException(page.getName()); } } }
@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); } }
SPage insertPage(final SPage page, final byte[] content) throws SObjectAlreadyExistsException, SObjectCreationException { final SPageLogBuilder logBuilder = getPageLog(ActionType.CREATED, "Adding a new page with name " + page.getName()); try { final SPageWithContent pageContent = new SPageWithContentImpl(page, content); final SPage pageByName = checkIfPageAlreadyExists(page); if (null != pageByName) { initiateLogBuilder(page.getId(), SQueriableLog.STATUS_FAIL, logBuilder, METHOD_NAME_ADD_PAGE); throwAlreadyExistsException(pageByName.getName()); } recorder.recordInsert(new InsertRecord(pageContent), PAGE); page.setId(pageContent.getId()); notifyPageInsert(page, content); return page; } catch (final SObjectCreationException ce) { throw ce; } catch (SRecorderException | SBonitaReadException re) { throw new SObjectCreationException(re); } }
private void deleteProfileEntry(final SPage sPage) throws SBonitaReadException, SProfileEntryNotFoundException, SProfileEntryDeletionException { final List<OrderByOption> orderByOptions = Collections .singletonList(new OrderByOption(SProfileEntry.class, SProfileEntryBuilderFactory.INDEX, OrderByType.ASC)); final List<FilterOption> filters = new ArrayList<>(); filters.add(new FilterOption(SProfileEntry.class, SProfileEntryBuilderFactory.PAGE, sPage.getName())); filters.add(new FilterOption(SProfileEntry.class, SProfileEntryBuilderFactory.CUSTOM, new Boolean(true))); final QueryOptions queryOptions = new QueryOptions(0, QueryOptions.UNLIMITED_NUMBER_OF_RESULTS, orderByOptions, filters, null); final List<SProfileEntry> searchProfileEntries = profileService.searchProfileEntries(queryOptions); for (final SProfileEntry sProfileEntry : searchProfileEntries) { profileService.deleteProfileEntry(sProfileEntry.getId()); if (sProfileEntry.getParentId() > 0) { deleteParentIfNoMoreChildren(sProfileEntry); } } }
@Override public void pageDeleted(final SPage page) throws SBonitaReadException, SDeletionException { if (SContentType.API_EXTENSION.equals(page.getContentType())) { List<SPageMapping> mappings; do { mappings = pageMappingService.get(page.getId(), 0, MAX_RESULTS); for (final SPageMapping mapping : mappings) { pageMappingService.delete(mapping); } } while (mappings.size() == MAX_RESULTS); } }
private void deletePage(final SPage sPage) throws SObjectModificationException { final SPageLogBuilder logBuilder = getPageLog(ActionType.DELETED, "Deleting page named: " + sPage.getName()); try { deleteProfileEntry(sPage); for (final PageServiceListener pageServiceListener : pageServiceListeners) { pageServiceListener.pageDeleted(sPage); } recorder.recordDelete(new DeleteRecord(sPage), PAGE); initiateLogBuilder(sPage.getId(), SQueriableLog.STATUS_OK, logBuilder, METHOD_DELETE_PAGE); } catch (SRecorderException | SBonitaReadException | SProfileEntryNotFoundException | SProfileEntryDeletionException | SDeletionException re) { initiateLogBuilder(sPage.getId(), SQueriableLog.STATUS_FAIL, logBuilder, METHOD_DELETE_PAGE); throw new SObjectModificationException(re); } }