Commit 79b13bae authored by Dumitru Corini's avatar Dumitru Corini Committed by GitHub
Browse files

feat(applications): add rest api default apps information (#698)

Add new fields on the application:
* editable field
* visibility field

covers [RUNTIME-286](https://bonitasoft.atlassian.net/browse/RUNTIME-286)
parent 741e39d7
......@@ -53,6 +53,8 @@ public class ApplicationDefinition extends ItemDefinition<ApplicationItem> {
createAttribute(ApplicationItem.ATTRIBUTE_LAST_UPDATE_DATE, ItemAttribute.TYPE.STRING);
createAttribute(ApplicationItem.ATTRIBUTE_UPDATED_BY, ItemAttribute.TYPE.ITEM_ID);
createAttribute(ApplicationItem.ATTRIBUTE_STATE, ItemAttribute.TYPE.STRING);
createAttribute(ApplicationItem.ATTRIBUTE_VISIBILITY, ItemAttribute.TYPE.STRING);
createAttribute(ApplicationItem.ATTRIBUTE_EDITABLE, ItemAttribute.TYPE.BOOLEAN);
}
@Override
......
......@@ -13,6 +13,7 @@
**/
package org.bonitasoft.web.rest.model.application;
import org.bonitasoft.engine.business.application.ApplicationVisibility;
import org.bonitasoft.web.rest.model.portal.page.PageItem;
import org.bonitasoft.web.toolkit.client.data.APIID;
import org.bonitasoft.web.toolkit.client.data.item.IItem;
......@@ -56,6 +57,10 @@ public class ApplicationItem extends Item implements ItemHasUniqueId, ItemHasIco
public static final String ATTRIBUTE_THEME_ID = "themeId";
public static final String ATTRIBUTE_VISIBILITY = "visibility";
public static final String ATTRIBUTE_EDITABLE = "editable";
public static final String FILTER_USER_ID = "userId";
public static final String ICON_PATH_API_PREFIX = "../API/applicationIcon/";
......@@ -223,6 +228,23 @@ public class ApplicationItem extends Item implements ItemHasUniqueId, ItemHasIco
setAttribute(FILTER_USER_ID, userId);
}
public String getVisibility() {
return getAttributeValue(ATTRIBUTE_VISIBILITY);
}
/** FIXME Use Enum instead of String after removing GWT permutations */
public void setVisibility(final String visibility) {
setAttribute(ATTRIBUTE_VISIBILITY, visibility);
}
public boolean isEditable() {
return Boolean.parseBoolean(getAttributeValue(ATTRIBUTE_EDITABLE));
}
public void setEditable(final boolean isEditable) {
setAttribute(ATTRIBUTE_EDITABLE, String.valueOf(isEditable));
}
public PageItem getLayout() {
return (PageItem) getDeploy(ATTRIBUTE_LAYOUT_ID);
}
......
......@@ -24,13 +24,9 @@ import org.bonitasoft.engine.business.application.Application;
import org.bonitasoft.engine.business.application.ApplicationCreator;
import org.bonitasoft.engine.business.application.ApplicationUpdater;
import org.bonitasoft.web.rest.model.application.ApplicationItem;
import org.bonitasoft.web.rest.model.identity.GroupItem;
import org.bonitasoft.web.rest.server.datastore.organization.Avatars;
import org.bonitasoft.web.toolkit.client.common.util.MapUtil;
import org.bonitasoft.web.toolkit.client.data.item.template.ItemHasIcon;
import static org.bonitasoft.web.toolkit.client.common.util.StringUtil.isBlank;
/**
* @author Elias Ricken de Medeiros
*/
......@@ -49,7 +45,13 @@ public class ApplicationItemConverter {
item.setLastUpdateDate(Long.toString(application.getLastUpdateDate().getTime()));
item.setUpdatedBy(application.getUpdatedBy());
item.setState(application.getState());
item.setProfileId(application.getProfileId());
item.setVisibility(application.getVisibility().name());
item.setEditable(application.isEditable());
if (application.getProfileId() != null) {
item.setProfileId(application.getProfileId());
} else {
item.setProfileId(-1L);
}
if (application.getHomePageId() != null) {
item.setHomePageId(application.getHomePageId());
} else {
......
......@@ -16,11 +16,7 @@ import java.util.HashMap;
import org.bonitasoft.engine.api.ApplicationAPI;
import org.bonitasoft.engine.api.PageAPI;
import org.bonitasoft.engine.business.application.Application;
import org.bonitasoft.engine.business.application.ApplicationCreator;
import org.bonitasoft.engine.business.application.ApplicationNotFoundException;
import org.bonitasoft.engine.business.application.ApplicationPage;
import org.bonitasoft.engine.business.application.ApplicationUpdater;
import org.bonitasoft.engine.business.application.*;
import org.bonitasoft.engine.business.application.impl.ApplicationImpl;
import org.bonitasoft.engine.exception.CreationException;
import org.bonitasoft.engine.exception.DeletionException;
......@@ -245,6 +241,7 @@ public class ApplicationDataStoreTest extends APITestWithMock {
application.setId(1);
application.setCreationDate(new Date());
application.setLastUpdateDate(new Date());
application.setVisibility(ApplicationVisibility.ALL);
final ApplicationItem item = new ApplicationItem();
given(converter.toApplicationItem(application)).willReturn(item);
......@@ -287,6 +284,7 @@ public class ApplicationDataStoreTest extends APITestWithMock {
application.setId(1);
application.setCreationDate(new Date());
application.setLastUpdateDate(new Date());
application.setVisibility(ApplicationVisibility.ALL);
final ApplicationItem item = new ApplicationItem();
given(converter.toApplicationItem(application)).willReturn(item);
......
......@@ -11,10 +11,7 @@ import java.util.HashMap;
import java.util.Map;
import org.bonitasoft.console.common.server.utils.BonitaHomeFolderAccessor;
import org.bonitasoft.engine.business.application.ApplicationCreator;
import org.bonitasoft.engine.business.application.ApplicationField;
import org.bonitasoft.engine.business.application.ApplicationState;
import org.bonitasoft.engine.business.application.ApplicationUpdater;
import org.bonitasoft.engine.business.application.*;
import org.bonitasoft.engine.business.application.impl.ApplicationImpl;
import org.bonitasoft.web.rest.model.application.ApplicationItem;
import org.bonitasoft.web.rest.server.APITestWithMock;
......@@ -39,6 +36,7 @@ public class ApplicationItemConverterTest extends APITestWithMock {
private static final long LAYOUT_ID = 3L;
private static final long THEME_ID = 4L;
private static final long TENANT_ID = 43L;
private static final ApplicationVisibility APPLICATION_VISIBILITY = ApplicationVisibility.RESTRICTED;
private ApplicationItemConverter converter;
......@@ -61,6 +59,8 @@ public class ApplicationItemConverterTest extends APITestWithMock {
application.setState(STATE);
application.setProfileId(PROFILE_ID);
application.setHomePageId(HOME_PAGE_ID);
application.setVisibility(APPLICATION_VISIBILITY);
application.setEditable(true);
//when
ApplicationItem item = converter.toApplicationItem(application);
......@@ -81,6 +81,8 @@ public class ApplicationItemConverterTest extends APITestWithMock {
assertThat(item.getProfileId().toLong()).isEqualTo(PROFILE_ID);
assertThat(item.getHomePageId().toLong()).isEqualTo(HOME_PAGE_ID);
assertThat(item.getLayoutId().toLong()).isEqualTo(LAYOUT_ID);
assertThat(item.getVisibility()).isEqualTo(APPLICATION_VISIBILITY.name());
assertThat(item.isEditable()).isEqualTo(true);
application.setHasIcon(false);
......@@ -102,6 +104,7 @@ public class ApplicationItemConverterTest extends APITestWithMock {
application.setState(STATE);
application.setProfileId(PROFILE_ID);
application.setHomePageId(null);
application.setVisibility(APPLICATION_VISIBILITY);
//when
final ApplicationItem item = converter.toApplicationItem(application);
......@@ -124,6 +127,7 @@ public class ApplicationItemConverterTest extends APITestWithMock {
application.setState(STATE);
application.setProfileId(PROFILE_ID);
application.setHomePageId(null);
application.setVisibility(APPLICATION_VISIBILITY);
//when
final ApplicationItem item = converter.toApplicationItem(application);
......@@ -146,6 +150,7 @@ public class ApplicationItemConverterTest extends APITestWithMock {
application.setState(STATE);
application.setProfileId(PROFILE_ID);
application.setHomePageId(null);
application.setVisibility(APPLICATION_VISIBILITY);
//when
final ApplicationItem item = converter.toApplicationItem(application);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment