Skip to content

Commit

Permalink
feat(advanced application): add licence check (#3035)
Browse files Browse the repository at this point in the history
* add licence check to advanced application filter
* move it to correct edition

Covers [BPM-105](https://bonitasoft.atlassian.net/browse/BPM-105)

Co-authored-by: Haroun EL ALAMI <[email protected]>
  • Loading branch information
abirembaut and Shmayro authored Jun 18, 2024
1 parent 7e13f9c commit a6357f6
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,19 @@
import static org.junit.Assert.*;
import static org.mockito.Mockito.spy;

import java.io.File;
import java.net.URL;
import java.io.InputStream;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.bonitasoft.console.common.server.preferences.constants.WebBonitaConstantsUtils;
import org.bonitasoft.engine.api.ApplicationAPI;
import org.bonitasoft.engine.api.PageAPI;
import org.bonitasoft.engine.api.TenantAPIAccessor;
import org.bonitasoft.engine.business.application.Application;
import org.bonitasoft.engine.business.application.ApplicationImportPolicy;
import org.bonitasoft.engine.exception.BonitaRuntimeException;
import org.bonitasoft.engine.page.Page;
import org.bonitasoft.engine.search.SearchOptions;
import org.bonitasoft.engine.search.SearchOptionsBuilder;
Expand Down Expand Up @@ -91,12 +89,8 @@ public void cleanPagesAndApplications() throws Exception {

private PageItem addPage(String pageFileName) throws Exception {
final PageItem pageItem = aPageItem().build();
final URL zipFileUrl = getClass().getResource(pageFileName);

final File zipFile = new File(zipFileUrl.toURI());
FileUtils.copyFileToDirectory(zipFile, WebBonitaConstantsUtils.getTenantInstance().getTempFolder());

final byte[] pageContent = FileUtils.readFileToByteArray(new File(zipFileUrl.toURI()));
final InputStream pageInputStream = getClass().getResourceAsStream(pageFileName);
final byte[] pageContent = IOUtils.toByteArray(pageInputStream);
return addPageItemToRepository(pageItem.getContentName(), pageContent);
}

Expand Down Expand Up @@ -162,7 +156,7 @@ public void should_update_LegacyApplication() throws Exception {
}

@Test
public void should_search_filter_AdvancedApplications() throws Exception {
public void should_search_not_support_filtering_on_AdvancedApplications() throws Exception {
// Given
var legacyApp = createLegacyApplication();

Expand All @@ -171,14 +165,15 @@ public void should_search_filter_AdvancedApplications() throws Exception {
final String orders = ApplicationItem.ATTRIBUTE_TOKEN + " DESC";
final HashMap<String, String> filters = new HashMap<>();
filters.put(ApplicationItem.ATTRIBUTE_ADVANCED, "true");
var searchResult = apiApplication.search(0, 1, search, orders, filters);

// Then
assertTrue(searchResult.getResults().isEmpty());
assertThrows(
"Expected exception: The search does not support filtering on advanced applications in this edition.",
BonitaRuntimeException.class, () -> apiApplication.search(0, 1, search, orders, filters));
}

private AbstractApplicationItem createLegacyApplication() throws Exception {
final PageItem pageItem = addPage(HOME_PAGE_ZIP);
addPage(HOME_PAGE_ZIP);
final PageItem layout = addPage(LAYOUT_ZIP);
final PageItem theme = addPage(THEME_ZIP);
final ApplicationItem legacyItem = ApplicationDefinition.get().createItem();
Expand All @@ -187,8 +182,6 @@ private AbstractApplicationItem createLegacyApplication() throws Exception {
legacyItem.setVersion("1.0");
legacyItem.setProfileId(2L);
legacyItem.setState("ACTIVATED");
// That's the default and gets saved as -1
// legacyItem.setHomePageId(pageItem.getId().toLong());
legacyItem.setLayoutId(layout.getId().toLong());
legacyItem.setThemeId(theme.getId().toLong());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ public class ApplicationSearchDescriptor {
*/
public static final String ID = "id";

/**
* Used to filter or order <code>Application</code> items by legacy or advanced criteria
*/
public static final String ADVANCED = "advanced";

/**
* Used to filter or order by the <code>Application</code> token
*/
Expand Down Expand Up @@ -123,4 +118,13 @@ public class ApplicationSearchDescriptor {
* @see Application
*/
public static final String USER_ID = "userId";

/**
* Used to filter or order <code>Application</code> items by legacy or advanced criteria
*
* @since 10.2.0 for some Subscription editions only
*/
public static final String ADVANCED = "advanced";
// keeping this constant here for convenience reasons
// having a subscription descriptor with just this field would not be user-friendly
}
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,11 @@ public SearchResult<IApplication> searchIApplications(final SearchOptions search
final ServiceAccessor serviceAccessor = getServiceAccessor();
final SearchApplicationDescriptor appSearchDescriptor = serviceAccessor.getSearchEntitiesDescriptor()
.getSearchApplicationDescriptor();
return internalSearchIApplications(serviceAccessor, appSearchDescriptor, searchOptions);
}

protected SearchResult<IApplication> internalSearchIApplications(ServiceAccessor serviceAccessor,
SearchApplicationDescriptor appSearchDescriptor, SearchOptions searchOptions) throws SearchException {
final ApplicationModelConverter converter = getApplicationModelConverter(serviceAccessor.getPageService());
final ApplicationService applicationService = serviceAccessor.getApplicationService();
final Optional<SearchFilter> filterOnUserId = searchOptions.getFilters().stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class SearchApplicationDescriptor extends SearchEntityDescriptor {

private final Map<Class<? extends PersistentObject>, Set<String>> allFields;

SearchApplicationDescriptor() {
protected SearchApplicationDescriptor() {
keys = new HashMap<>(13);
keys.put(ApplicationSearchDescriptor.ID,
new FieldDescriptor(SApplication.class, AbstractSApplication.ID));
Expand Down Expand Up @@ -61,8 +61,6 @@ public class SearchApplicationDescriptor extends SearchEntityDescriptor {
new FieldDescriptor(SApplication.class, AbstractSApplication.LAYOUT_ID));
keys.put(ApplicationSearchDescriptor.THEME_ID,
new FieldDescriptor(SApplication.class, AbstractSApplication.THEME_ID));
keys.put(ApplicationSearchDescriptor.ADVANCED,
new FieldDescriptor(SApplication.class, AbstractSApplication.ADVANCED));
// internal usage only for now (as it would require a conversion of the Visibility enum):
keys.put(APPLICATION_VISIBILITY,
new FieldDescriptor(SApplication.class, AbstractSApplication.INTERNAL_PROFILE));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
import org.bonitasoft.engine.api.PageAPI;
import org.bonitasoft.engine.api.TenantAPIAccessor;
import org.bonitasoft.engine.exception.BonitaException;
import org.bonitasoft.engine.exception.BonitaHomeNotSetException;
import org.bonitasoft.engine.exception.ServerAPIException;
import org.bonitasoft.engine.exception.UnknownAPITypeException;
import org.bonitasoft.engine.session.APISession;
import org.bonitasoft.web.toolkit.client.common.exception.api.APIException;

Expand All @@ -30,14 +33,24 @@ public ApplicationDataStore create(final APISession session) {
ApplicationAPI applicationAPI;
PageAPI pageAPI;
try {
applicationAPI = TenantAPIAccessor.getLivingApplicationAPI(session);
pageAPI = TenantAPIAccessor.getCustomPageAPI(session);
applicationAPI = getLivingApplicationAPI(session);
pageAPI = getCustomPageAPI(session);
return new ApplicationDataStore(session, applicationAPI, pageAPI, getApplicationConverter());
} catch (final BonitaException e) {
throw new APIException(e);
}
}

protected PageAPI getCustomPageAPI(APISession session)
throws BonitaHomeNotSetException, ServerAPIException, UnknownAPITypeException {
return TenantAPIAccessor.getCustomPageAPI(session);
}

protected ApplicationAPI getLivingApplicationAPI(APISession session)
throws BonitaHomeNotSetException, ServerAPIException, UnknownAPITypeException {
return TenantAPIAccessor.getLivingApplicationAPI(session);
}

protected ApplicationItemConverter getApplicationConverter() {
return new ApplicationItemConverter(new BonitaHomeFolderAccessor());
}
Expand Down

0 comments on commit a6357f6

Please sign in to comment.