Skip to content

Commit

Permalink
ADD & REPLACE keywords
Browse files Browse the repository at this point in the history
  • Loading branch information
angelborroy-ks committed Dec 18, 2017
1 parent a5e98e0 commit 46417a3
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 9 deletions.
34 changes: 33 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,36 @@ From Sample 2 Site > Values = 1,2
## Version 3.1.0

Added controls for default value and parent selection
Added controls for default value and parent selection

## Version 3.2.0

AMP artifacts ready-to-deploy available at [3.2.0](https://github.com/keensoft/alfresco-datalist-constraints/releases/tag/3.2.0)

Keywords `[ADD]` and `[REPLACE]` have been added to define the behaviour of a list inside a Site:

* `[ADD]` merges values from global Dictionary list and Site list
* `[REPLACE]` includes only values from Site list

This keyword has to be included in any place at `Description` field when declaring the list inside a Site.

** Sample scenario **

Datalist definitions

```
Dictionary Site > Datalist "Options" > Values = 1,2
Sample 1 Site > Datalist "Options" (including [ADD] in description) > Values = 3,4
Sample 2 Site > Datalist "Options" (including [REPLACE] in description) > Values = 3,4
Sample 3 Site > No datalist defined
```

Values provided by combos

```
Outside from a Site > Values = 1,2
From Advanced Search > Values = 1,2,3,4
From Sample 1 Site > Values = 1,2,3,4
From Sample 2 Site > Values = 3,4
From Sample 3 Site > Values = 1,2
```
2 changes: 1 addition & 1 deletion datalist-model-repo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>es.keensoft</groupId>
<artifactId>datalist-model-repo</artifactId>
<version>3.1.0</version>
<version>3.2.0</version>
<name>datalist-model-repo Repository AMP project</name>
<packaging>amp</packaging>
<description>Manages the lifecycle of the site-props-repo Repository AMP (Alfresco Module Package)</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,14 @@
import org.springframework.extensions.webscripts.WebScriptResponse;

import es.keensoft.alfresco.model.DatalistModel;
import es.keensoft.alfresco.model.DatalistModel.DataListStatus;

public class DataListWebScript extends AbstractWebScript {

private static final String JSON_CODE = "code";
private static final String REPLACE_DESK_MARK = "[REPLACE]";
private static final String ADD_DESC_MARK = "[ADD]";

private static final String JSON_CODE = "code";
private static final String JSON_VALUE = "value";

private static final String DATALIST_CONTAINER_ID = "dataLists";
Expand Down Expand Up @@ -71,8 +75,21 @@ public void execute(WebScriptRequest request, WebScriptResponse response) throws
siteId = siteInfo.getShortName();
}
}
if (siteId != null && existsDatalist(siteId, targetedDataListName)) {
sites.add(siteService.getSite(siteId));
DataListStatus siteStatus = DataListStatus.NONE;
if (siteId != null) {
siteStatus = existsDatalist(siteId, targetedDataListName);
switch(siteStatus) {
case NONE:
sites = siteService.listSites(null, DATALIST_PRESET);
break;
case ADD:
sites = siteService.listSites(null, DATALIST_PRESET);
sites.add(siteService.getSite(siteId));
break;
case REPLACE:
sites.add(siteService.getSite(siteId));
break;
}
} else {
sites = siteService.listSites(null, DATALIST_PRESET);
}
Expand Down Expand Up @@ -168,18 +185,29 @@ public int compare(Map.Entry<String, String> o1,
return sortedMap;
}

private boolean existsDatalist(String siteId, String targetedDataListName) {
private DataListStatus existsDatalist(String siteId, String targetedDataListName) {

NodeRef dataListContainer = SiteServiceImpl.getSiteContainer(siteId, DATALIST_CONTAINER_ID, true, siteService, transactionService, taggingService);
List<ChildAssociationRef> dataListsNodes = nodeService.getChildAssocs(dataListContainer);
for (ChildAssociationRef dataList : dataListsNodes) {
if (dataList.getTypeQName().isMatch(ContentModel.ASSOC_CONTAINS)) {
if (nodeService.getProperty(dataList.getChildRef(), ContentModel.PROP_TITLE).toString().equals(targetedDataListName)) {
return true;
Object description = nodeService.getProperty(dataList.getChildRef(), ContentModel.PROP_DESCRIPTION);
if (description != null) {
if (description.toString().indexOf(ADD_DESC_MARK) > 0) {
return DataListStatus.ADD;
} else if (description.toString().indexOf(REPLACE_DESK_MARK) > 0) {
return DataListStatus.REPLACE;
} else {
return DataListStatus.REPLACE;
}
} else {
return DataListStatus.REPLACE;
}
}
}
}
return false;
return DataListStatus.NONE;

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ public class DatalistModel {
public static final QName DATALIST_MODEL_VALUE_PROPERTY = QName.createQName(DATALIST_MODEL_URI, "value");
public static final QName DATALIST_MODEL_ITEM_TYPE = QName.createQName(DATALIST_MODEL_URI, "optionList");

public enum DataListStatus {
ADD, REPLACE, NONE
}

}
2 changes: 1 addition & 1 deletion datalist-model-share/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>es.keensoft</groupId>
<artifactId>datalist-model-share</artifactId>
<version>3.1.0</version>
<version>3.2.0</version>
<name>site-props-share AMP project</name>
<packaging>amp</packaging>
<description>Manages the lifecycle of the site-props-share AMP (Alfresco Module Package)</description>
Expand Down

0 comments on commit 46417a3

Please sign in to comment.