Skip to content

Commit b62696a

Browse files
Initial commit
0 parents  commit b62696a

File tree

21 files changed

+606
-0
lines changed

21 files changed

+606
-0
lines changed

datalist-model-repo/pom.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
4+
5+
<parent>
6+
<artifactId>alfresco-datalist</artifactId>
7+
<groupId>es.keensoft</groupId>
8+
<version>1.0.0</version>
9+
</parent>
10+
11+
<modelVersion>4.0.0</modelVersion>
12+
<artifactId>datalist-model-repo</artifactId>
13+
<packaging>amp</packaging>
14+
<name>Alfresco components :: DataList Model</name>
15+
</project>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>
3+
4+
<beans>
5+
6+
<bean id="extension.dlm.dictionaryBootstrap" parent="dictionaryModelBootstrap" depends-on="dictionaryBootstrap">
7+
<property name="models">
8+
<list>
9+
<value>alfresco/extension/model/datalist-model.xml</value>
10+
<value>alfresco/extension/model/custom-model.xml</value>
11+
</list>
12+
</property>
13+
</bean>
14+
<bean id="extension.dlm.resourceBundle" class="org.alfresco.i18n.ResourceBundleBootstrapComponent">
15+
<property name="resourceBundles">
16+
<list>
17+
<value>alfresco.messages.datalist-model</value>
18+
<value>alfresco.messages.custom-model</value>
19+
</list>
20+
</property>
21+
</bean>
22+
23+
<bean id="webscript.es.keensoft.datalist.datalist.get"
24+
class="es.keensoft.alfresco.action.webscript.DataListWebScript" parent="webscript">
25+
<property name="nodeService" ref="NodeService"/>
26+
<property name="siteService" ref="SiteService"/>
27+
<property name="transactionService" ref="TransactionService" />
28+
<property name="taggingService" ref="TaggingService" />
29+
<!-- TODO Customize this value with Site shortname used to manage option lists -->
30+
<property name="publicSiteName" value="administration" />
31+
</bean>
32+
33+
</beans>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<model name="ks:samplemodel" xmlns="http://www.alfresco.org/model/dictionary/1.0">
4+
<description>Sample model for datalists option values</description>
5+
<author>keensoft</author>
6+
<version>1.0</version>
7+
8+
<imports>
9+
<import uri="http://www.alfresco.org/model/dictionary/1.0" prefix="d" />
10+
<import uri="http://www.alfresco.org/model/content/1.0" prefix="cm" />
11+
</imports>
12+
13+
<namespaces>
14+
<namespace uri="http://www.alfresco.com/model/keensoft/1.0" prefix="ks" />
15+
</namespaces>
16+
17+
<aspects>
18+
<aspect name="ks:sample">
19+
<title>Sample</title>
20+
<properties>
21+
<property name="ks:option">
22+
<title>Option</title>
23+
<description>Option</description>
24+
<type>d:text</type>
25+
</property>
26+
<property name="ks:anotherOption">
27+
<title>Another option</title>
28+
<description>Another option</description>
29+
<type>d:text</type>
30+
</property>
31+
</properties>
32+
</aspect>
33+
</aspects>
34+
35+
</model>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<model name="dlm:datalistsmodel" xmlns="http://www.alfresco.org/model/dictionary/1.0">
4+
<description>HTML Option list values</description>
5+
<author>keensoft</author>
6+
<version>1.0</version>
7+
8+
<imports>
9+
<import uri="http://www.alfresco.org/model/dictionary/1.0" prefix="d"/>
10+
<import uri="http://www.alfresco.org/model/content/1.0" prefix="cm"/>
11+
<import uri="http://www.alfresco.org/model/datalist/1.0" prefix="dl"/>
12+
13+
</imports>
14+
15+
<namespaces>
16+
<namespace uri="http://www.alfresco.com/model/datalistmodel/1.0" prefix="dlm" />
17+
</namespaces>
18+
19+
<types>
20+
21+
<type name="dlm:optionList">
22+
<title>Options</title>
23+
<parent>dl:dataListItem</parent>
24+
<properties>
25+
<property name="dlm:code">
26+
<title>Code</title>
27+
<type>d:text</type>
28+
</property>
29+
<property name="dlm:value">
30+
<title>Value</title>
31+
<type>d:text</type>
32+
</property>
33+
</properties>
34+
</type>
35+
36+
</types>
37+
38+
</model>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<webscript>
2+
<shortname>Get datalist values</shortname>
3+
<description>Get datalist values from customized items
4+
To test: curl -v -u admin:admin "http://localhost:8080/alfresco/service/keensoft/datalist/{name}"
5+
</description>
6+
<url>/keensoft/datalist/{name}</url>
7+
<format default="json"/>
8+
<authentication>user</authentication>
9+
<transaction>none</transaction>
10+
</webscript>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
aspect.ks_sample=Sample
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
type.dlm_optionList=Option list
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Custom AMP to WAR location mappings
2+
3+
#
4+
# The following property can be used to include the standard set of mappings.
5+
# The contents of this file will override any defaults. The default is
6+
# 'true', i.e. the default mappings will be augmented or modified by values in
7+
# this file.
8+
#
9+
include.default=true
10+
11+
#
12+
# Custom mappings. If 'include.default' is false, then this is the complete set.
13+
#
14+
/components=/components
15+
/config=/WEB-INF/classes
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.id=${project.artifactId}
2+
module.title=${project.name}
3+
module.description=${project.description}
4+
module.version=${noSnapshotVersion}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
package es.keensoft.alfresco.action.webscript;
2+
3+
import java.io.IOException;
4+
import java.util.List;
5+
6+
import org.alfresco.model.ContentModel;
7+
import org.alfresco.repo.site.SiteServiceImpl;
8+
import org.alfresco.service.cmr.repository.ChildAssociationRef;
9+
import org.alfresco.service.cmr.repository.NodeRef;
10+
import org.alfresco.service.cmr.repository.NodeService;
11+
import org.alfresco.service.cmr.site.SiteService;
12+
import org.alfresco.service.cmr.tagging.TaggingService;
13+
import org.alfresco.service.namespace.RegexQNamePattern;
14+
import org.alfresco.service.transaction.TransactionService;
15+
import org.json.JSONArray;
16+
import org.json.JSONObject;
17+
import org.springframework.extensions.webscripts.AbstractWebScript;
18+
import org.springframework.extensions.webscripts.WebScriptRequest;
19+
import org.springframework.extensions.webscripts.WebScriptResponse;
20+
21+
import es.keensoft.alfresco.model.DatalistModel;
22+
23+
public class DataListWebScript extends AbstractWebScript {
24+
25+
private static final String JSON_CODE = "code";
26+
private static final String JSON_VALUE = "value";
27+
28+
private static final String DATALIST_CONTAINER_ID = "dataLists";
29+
30+
private NodeService nodeService;
31+
private SiteService siteService;
32+
private TransactionService transactionService;
33+
private TaggingService taggingService;
34+
private String publicSiteName;
35+
36+
@Override
37+
public void execute(WebScriptRequest request, WebScriptResponse response) throws IOException {
38+
39+
String targetedDataListName = request.getExtensionPath();
40+
41+
JSONArray objProcess = new JSONArray();
42+
43+
try {
44+
45+
NodeRef dataListContainer = SiteServiceImpl.getSiteContainer(publicSiteName, DATALIST_CONTAINER_ID, true, siteService, transactionService, taggingService);
46+
List<ChildAssociationRef> dataListsNodes = nodeService.getChildAssocs(dataListContainer);
47+
48+
for (ChildAssociationRef dataList : dataListsNodes) {
49+
50+
if (dataList.getTypeQName().isMatch(ContentModel.ASSOC_CONTAINS)) {
51+
52+
if (nodeService.getProperty(dataList.getChildRef(), ContentModel.PROP_TITLE).toString().equals(targetedDataListName)) {
53+
54+
List<ChildAssociationRef> itemsNodes = nodeService.getChildAssocs(dataList.getChildRef(), ContentModel.ASSOC_CONTAINS, RegexQNamePattern.MATCH_ALL);
55+
56+
for (ChildAssociationRef item : itemsNodes) {
57+
58+
if (nodeService.getType(item.getChildRef()).isMatch(DatalistModel.DATALIST_MODEL_ITEM_TYPE)) {
59+
JSONObject obj = new JSONObject();
60+
obj.put(JSON_CODE, nodeService.getProperty(item.getChildRef(), DatalistModel.DATALIST_MODEL_CODE_PROPERTY).toString());
61+
obj.put(JSON_VALUE, nodeService.getProperty(item.getChildRef(), DatalistModel.DATALIST_MODEL_VALUE_PROPERTY).toString());
62+
objProcess.put(obj);
63+
} else {
64+
// Ignore other datalist types
65+
continue;
66+
}
67+
}
68+
69+
}
70+
71+
}
72+
73+
}
74+
75+
} catch (Exception e) {
76+
throw new IOException(e);
77+
}
78+
79+
String jsonString = objProcess.toString();
80+
response.setContentEncoding("UTF-8");
81+
response.getWriter().write(jsonString);
82+
83+
}
84+
85+
public void setNodeService(NodeService nodeService) {
86+
this.nodeService = nodeService;
87+
}
88+
89+
public void setSiteService(SiteService siteService) {
90+
this.siteService = siteService;
91+
}
92+
93+
public void setPublicSiteName(String publicSiteName) {
94+
this.publicSiteName = publicSiteName;
95+
}
96+
97+
public void setTransactionService(TransactionService transactionService) {
98+
this.transactionService = transactionService;
99+
}
100+
101+
public void setTaggingService(TaggingService taggingService) {
102+
this.taggingService = taggingService;
103+
}
104+
105+
}

0 commit comments

Comments
 (0)