Skip to content

Commit

Permalink
MGR-76 support filtering sites (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
madness-inc committed Aug 1, 2019
1 parent 565d734 commit 818c7a1
Show file tree
Hide file tree
Showing 8 changed files with 204 additions and 6 deletions.
6 changes: 5 additions & 1 deletion application-home/conf/datasources/ds-sites.xml
Expand Up @@ -8,7 +8,10 @@
<permissions>
<permission ref="site.list" mode="set" />
</permissions>
<params />
<params>
<param name="name" />
<param name="domain" />
</params>
<meta-data bindClass="org.appng.api.model.Site">
<field name="name" type="text">
<sort prio="0" order="asc" ignore-case="true" />
Expand Down Expand Up @@ -78,6 +81,7 @@
</linkpanel>
</config>
<bean id="sites">
<option name="site" siteName="${name}" siteDomain="${domain}"/>
</bean>
</datasource>

Expand Down
6 changes: 6 additions & 0 deletions application-home/conf/pages/pg-sites.xml
Expand Up @@ -38,6 +38,8 @@
<get-param name="fUsr" />
<get-param name="fEtr" />
<get-param name="fCtpe" />
<get-param name="f_sn" />
<get-param name="f_sd" />
</get-params>
<post-params>
<post-param name="form_action" />
Expand All @@ -51,6 +53,10 @@
<element>
<datasource id="sites">
<condition expression="${empty action}" />
<params>
<param name="name">${f_sn}</param>
<param name="domain">${f_sd}</param>
</params>
</datasource>
</element>
</section>
Expand Down
Expand Up @@ -104,7 +104,9 @@ public DataContainer getData(Site site, Application application, Environment env
data = service.getNewSite(fp);
} else {
try {
data = service.searchSites(environment, fp, siteId);
String name = options.getString(SITE, "siteName");
String domain = options.getString(SITE, "siteDomain");
data = service.searchSites(environment, fp, siteId, name, domain);
} catch (BusinessException e) {
String message = request.getMessage(e.getMessageKey(), e.getMessageArgs());
log.error(message, e);
Expand Down
Expand Up @@ -142,6 +142,8 @@ public class ManagerService extends CoreService implements Service {

private Logger logger = LoggerFactory.getLogger(ManagerService.class);
private static final String FILTER_GROUP_NAME = "f_gn";
private static final String FILTER_SITE_NAME = "f_sn";
private static final String FILTER_SITE_DOMAIN = "f_sd";

private SelectionFactory selectionFactory;
private OptionGroupFactory optionGroupFactory;
Expand Down Expand Up @@ -930,7 +932,7 @@ private void checkUniqueRepositoryName(Request request, Repository repository, F
}
}

public DataContainer searchSites(Environment environment, FieldProcessor fp, Integer siteId)
public DataContainer searchSites(Environment environment, FieldProcessor fp, Integer siteId, String name, String domain)
throws BusinessException {
DataContainer data = new DataContainer(fp);
if (siteId != null) {
Expand All @@ -941,15 +943,33 @@ public DataContainer searchSites(Environment environment, FieldProcessor fp, Int
addSelectionsForSite(site, data);
data.setItem(new SiteForm(site));
} else {
SearchQuery<SiteImpl> siteQuery = siteRepository.createSearchQuery();
if (StringUtils.isNotBlank(name)) {
siteQuery.contains("name", name);
}
if (StringUtils.isNotBlank(domain)) {
siteQuery.contains("domain", domain);
}
Page<SiteImpl> sites = siteRepository.search(siteQuery, fp.getPageable());

Map<String, Site> siteMap = environment.getAttribute(Scope.PLATFORM, Platform.Environment.SITES);
Page<SiteImpl> sites = siteRepository.search(fp.getPageable());
for (SiteImpl siteImpl : sites) {
Site site = siteMap.get(siteImpl.getName());
if (null != site) {
siteImpl.setRunning(SiteState.STARTED.equals(site.getState()));
siteImpl.setStartupTime(site.getStartupTime());
}
}
Selection nameFilter = new SelectionBuilder<String>(FILTER_SITE_NAME)
.defaultOption(FILTER_SITE_NAME, name).title(MessageConstants.NAME).type(SelectionType.TEXT)
.select(name).build();
Selection domainFilter = new SelectionBuilder<String>(FILTER_SITE_DOMAIN)
.defaultOption(FILTER_SITE_DOMAIN, domain).title(MessageConstants.DOMAIN).type(SelectionType.TEXT)
.select(domain).build();
SelectionGroup filter = new SelectionGroup();
filter.getSelections().add(nameFilter);
filter.getSelections().add(domainFilter);
data.getSelectionGroups().add(filter);
data.setPage(sites);
}
return data;
Expand Down
Expand Up @@ -109,7 +109,7 @@ DataContainer searchResources(Request request, Site site, FieldProcessor fp, Res

DataContainer searchRole(FieldProcessor fp, Integer roleId, Integer appId) throws BusinessException;

DataContainer searchSites(Environment environment, FieldProcessor fp, Integer siteId) throws BusinessException;
DataContainer searchSites(Environment environment, FieldProcessor fp, Integer siteId, String name, String domain) throws BusinessException;

DataContainer searchSubjects(Request request, FieldProcessor fp, Integer subjectId, String defaultTimezone,
List<String> languages) throws BusinessException;
Expand Down
Expand Up @@ -18,9 +18,11 @@
import java.io.IOException;

import org.appng.api.FieldProcessor;
import org.appng.api.Platform;
import org.appng.api.ProcessingException;
import org.appng.api.support.CallableAction;
import org.appng.api.support.CallableDataSource;
import org.appng.application.manager.form.PropertyForm;
import org.appng.application.manager.form.SiteForm;
import org.appng.core.domain.SiteImpl;
import org.junit.FixMethodOrder;
Expand All @@ -41,6 +43,13 @@ public void testCreateSite() throws Exception {
siteToCreate.setDomain("localhost");
siteToCreate.setActive(true);

//prepares using appNG >= 1.19.1
PropertyForm form = new PropertyForm();
form.getProperty().setName(Platform.Property.MESSAGING_ENABLED);
form.getProperty().setDefaultString(Boolean.FALSE.toString());
getAction("propertyEvent", "create-platform-property").withParam(FORM_ACTION, "create-platform-property")
.getCallableAction(form).perform();

CallableAction callableAction = getAction(SITE_EVENT, "create").withParam(FORM_ACTION, "create")
.getCallableAction(siteForm);

Expand Down Expand Up @@ -93,6 +102,15 @@ public void testShowSites() throws Exception {
validate(siteDatasource.getDatasource());
}

@Test
public void testShowSitesFiltered() throws Exception {
CallableDataSource siteDatasource = getDataSource("sites").withParam("name", "site")
.withParam("domain", "example").getCallableDataSource();
siteDatasource.perform("test");

validate(siteDatasource.getDatasource());
}

private void createSite() {
SiteImpl realSite = new SiteImpl();
realSite.setName("site2");
Expand Down
15 changes: 14 additions & 1 deletion src/test/resources/xml/SitesTest-testShowSites.xml
Expand Up @@ -5,7 +5,10 @@
<permissions>
<permission ref="site.list" mode="set"></permission>
</permissions>
<params />
<params>
<param name="name" />
<param name="domain" />
</params>
<meta-data bindClass="org.appng.api.model.Site">
<field name="name" type="text" binding="name">
<sort />
Expand Down Expand Up @@ -75,6 +78,16 @@
</linkpanel>
</config>
<data>
<selectionGroup>
<selection id="f_sn" type="text">
<title id="name">Name</title>
<option value="" name="f_sn" />
</selection>
<selection id="f_sd" type="text">
<title id="domain">Domain</title>
<option value="" name="f_sd" />
</selection>
</selectionGroup>
<resultset chunk="0" chunkname="sites" chunksize="10" nextchunk="0" previouschunk="0" firstchunk="0"
lastchunk="0" hits="2">
<result>
Expand Down
135 changes: 135 additions & 0 deletions src/test/resources/xml/SitesTest-testShowSitesFiltered.xml
@@ -0,0 +1,135 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<datasource xmlns="http://www.appng.org/schema/platform" id="sites">
<config>
<title id="sites">Sites</title>
<permissions>
<permission ref="site.list" mode="set"></permission>
</permissions>
<params>
<param name="name">site</param>
<param name="domain">example</param>
</params>
<meta-data bindClass="org.appng.api.model.Site">
<field name="name" type="text" binding="name">
<sort />
<label id="name">Name</label>
</field>
<field name="host" type="text" binding="host">
<sort />
<label id="host">Host</label>
</field>
<field name="domain" type="text" binding="domain">
<sort />
<label id="domain">Domain</label>
</field>
<field name="description" type="text" binding="description">
<label id="description">Description</label>
</field>
<field name="active" type="image" binding="active">
<sort />
<label id="active">Active</label>
<icon condition="${current.active}">led_green</icon>
<icon condition="${!current.active}">led_red</icon>
</field>
<field name="running" type="image" binding="running">
<label id="running">Running</label>
<icon condition="${current.running}">led_green</icon>
<icon condition="${!current.running}">led_red</icon>
</field>
<field name="startupTime" type="date" format="yyyy-MM-dd HH:mm:ss" binding="startupTime">
<label id="startupTime">Startup time</label>
</field>
<field name="actions" type="linkpanel" binding="actions">
<label id="actions">Actions</label>
</field>
</meta-data>
<linkpanel id="other" location="both">
<link id="other[1]" mode="intern" target="/sites/create">
<permissions>
<permission ref="site.create" mode="set"></permission>
</permissions>
<label id="site.create">Create site</label>
<icon>new</icon>
</link>
</linkpanel>
<linkpanel id="actions" location="inline">
<link id="actions[1]" mode="intern" target="/sites/update/${current.id}" default="true">
<permissions>
<permission ref="site.edit" mode="set"></permission>
</permissions>
<label id="edit">Edit</label>
<icon>edit</icon>
</link>
<link id="actions[2]" mode="intern" target="/sites?form_action=delete&amp;siteid=${current.id}">
<permissions>
<permission ref="site.delete" mode="set"></permission>
</permissions>
<label id="delete">Delete</label>
<icon>delete</icon>
<confirmation id="site.delete.confirm" params="#{name}">Do you really want to delete the site "#{name}"?</confirmation>
</link>
<link id="actions[3]" mode="intern" target="/sites?form_action=reload&amp;siteid=${current.id}">
<permissions>
<permission ref="site.reload" mode="set"></permission>
</permissions>
<label id="reload">Reload</label>
<icon>reload</icon>
</link>
</linkpanel>
</config>
<data>
<selectionGroup>
<selection id="f_sn" type="text">
<title id="name">Name</title>
<option value="site" name="f_sn" />
</selection>
<selection id="f_sd" type="text">
<title id="domain">Domain</title>
<option value="example" name="f_sd" />
</selection>
</selectionGroup>
<resultset chunk="0" chunkname="sites" chunksize="10" nextchunk="0" previouschunk="0" firstchunk="0"
lastchunk="0" hits="1">
<result>
<field name="name" type="text">
<value>site2</value>
</field>
<field name="host" type="text">
<value>example.com</value>
</field>
<field name="domain" type="text">
<value>example.com</value>
</field>
<field name="description" type="text">
<value>a description</value>
</field>
<field name="active" type="image">
<value>true</value>
<icon type="class">led_green</icon>
</field>
<field name="running" type="image">
<value>false</value>
<icon type="class">led_red</icon>
</field>
<field name="startupTime" type="date">
<value></value>
</field>
<linkpanel id="actions" location="inline">
<link id="actions[1]" mode="intern" target="/sites/update/3" default="true">
<label id="edit">Edit</label>
<icon>edit</icon>
</link>
<link id="actions[2]" mode="intern" target="/sites?form_action=delete&amp;siteid=3">
<label id="delete">Delete</label>
<icon>delete</icon>
<confirmation id="site.delete.confirm" params="#{name}">Do you really want to delete the site "site2"?</confirmation>
</link>
<link id="actions[3]" mode="intern" target="/sites?form_action=reload&amp;siteid=3">
<label id="reload">Reload</label>
<icon>reload</icon>
</link>
</linkpanel>
</result>
</resultset>
</data>
</datasource>

0 comments on commit 818c7a1

Please sign in to comment.