Skip to content

Commit 6f44cee

Browse files
committed
close #41 cmis entry abstraction
1 parent 95f99f6 commit 6f44cee

File tree

4 files changed

+94
-80
lines changed

4 files changed

+94
-80
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
define([
2+
"dojo/_base/declare",
3+
"dojo/_base/array",
4+
"softwareloop/cmis/cmis",
5+
"softwareloop/util/browser"
6+
], function (declare, array, cmis, browser) {
7+
return declare(null, {
8+
constructor: function (entryNode) {
9+
this.id = entryNode.getElementsByTagName("id")[0].firstChild.nodeValue.substring(9);
10+
this.attributes = {};
11+
this.parseProperties(entryNode, "propertyId",
12+
function (stringValue) {
13+
return stringValue;
14+
}
15+
);
16+
this.parseProperties(entryNode, "propertyString",
17+
function (stringValue) {
18+
return stringValue;
19+
}
20+
);
21+
this.parseProperties(entryNode, "propertyInteger", parseInt);
22+
23+
this.parseProperties(entryNode, "propertyBoolean",
24+
function (stringValue) {
25+
return stringValue === 'true';
26+
}
27+
);
28+
this.parseProperties(entryNode, "propertyDateTime", cmis.parseDate);
29+
},
30+
31+
parseProperties: function (entryNode, tagName, converter) {
32+
var propertyStrings =
33+
browser.getElementsByTagName(entryNode, "cmis", tagName);
34+
for (var i = 0; i < propertyStrings.length; i++) {
35+
var propertyString = propertyStrings[i];
36+
var cmisAttributeName =
37+
propertyString.getAttribute("propertyDefinitionId");
38+
var attribute = {
39+
tagName: tagName,
40+
values: [],
41+
value: function () {
42+
return (this.values.length > 0) ? this.values[0] : null
43+
}
44+
};
45+
this.attributes[cmisAttributeName] = attribute;
46+
var valueNode = browser.getElementsByTagName(propertyString, "cmis", "value");
47+
if (valueNode) {
48+
array.forEach(valueNode, function (current) {
49+
var cmisAttributeValue = null;
50+
try {
51+
var nodeValue = current.firstChild.nodeValue;
52+
cmisAttributeValue = converter(nodeValue);
53+
} catch (e) {
54+
cmisAttributeValue = null;
55+
}
56+
attribute.values.push(cmisAttributeValue);
57+
});
58+
}
59+
}
60+
},
61+
62+
getAttributeValues: function (name) {
63+
var attribute = this.attributes[name];
64+
return attribute ? attribute.values : [];
65+
},
66+
67+
getAttributeValue: function (name) {
68+
var attributeValues = this.getAttributeValues(name);
69+
return (attributeValues.length > 0) ? attributeValues[0] : null;
70+
}
71+
72+
});
73+
});

src/main/amp/web/js/softwareloop/util/cmis.js renamed to src/main/amp/web/js/softwareloop/cmis/cmis.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ define([
4848
for (var cmisAttributeName in entryAttributes) {
4949
if (entryAttributes.hasOwnProperty(cmisAttributeName)) {
5050
var entryAttribute = entryAttributes[cmisAttributeName];
51-
console.log(entryAttribute);
5251
var elementName = "cmis:" + entryAttribute.tagName;
5352
xb.openElement(elementName);
5453
xb.addAttribute("propertyDefinitionId", cmisAttributeName);

src/main/amp/web/js/softwareloop/inboxes/Inbox.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ define([
1616
"dojo/_base/lang",
1717
"dojo/topic",
1818
"softwareloop/util/browser",
19-
"softwareloop/util/cmis",
19+
"softwareloop/cmis/cmis",
20+
"softwareloop/cmis/Entry",
2021
"dojo/_base/array"
21-
], function (TemplatedMixin, AttachMixin, WidgetBase, Core, declare, template, xhr, domClass, registry, hash, lang, topic, browser, cmis, array) {
22+
], function (TemplatedMixin, AttachMixin, WidgetBase, Core, declare, template, xhr, domClass, registry, hash, lang, topic, browser, cmis, Entry, array) {
2223
return declare([WidgetBase, TemplatedMixin, Core, AttachMixin], {
2324
templateString: template,
2425

@@ -123,8 +124,9 @@ define([
123124
try {
124125
var i;
125126
var items = [];
126-
var entries = this.data.getElementsByTagName("entry");
127-
array.forEach(entries, function (entry) {
127+
var entryNodes = this.data.getElementsByTagName("entry");
128+
array.forEach(entryNodes, function (entryNode) {
129+
var entry = new Entry(entryNode);
128130
var item = new itemClass({entry: entry});
129131
items.push(item);
130132
});

src/main/amp/web/js/softwareloop/inboxes/Item.js

Lines changed: 15 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,8 @@ define([
1010
"dojo/date/locale",
1111
"alfresco/dialogs/AlfDialog",
1212
"alfresco/core/Core",
13-
"dojo/_base/lang",
14-
"dojo/_base/array",
15-
"softwareloop/util/browser",
16-
"softwareloop/util/cmis"
17-
], function (TemplatedMixin, WidgetBase, declare, template, locale, AlfDialog, Core, lang, array, browser, cmis) {
13+
"dojo/_base/lang"
14+
], function (TemplatedMixin, WidgetBase, declare, template, locale, AlfDialog, Core, lang) {
1815
return declare([WidgetBase, TemplatedMixin, Core], {
1916
templateString: template,
2017

@@ -28,8 +25,6 @@ define([
2825

2926

3027
entry: null,
31-
entryId: null,
32-
entryAttributes: null,
3328

3429
previewUrl: "",
3530
downloadUrl: "",
@@ -44,71 +39,16 @@ define([
4439
downloadLabel: "download",
4540

4641
postMixInProperties: function () {
47-
this.bindToEntry();
4842
this.composeLines();
4943
},
5044

51-
bindToEntry: function () {
52-
this.entryId = this.entry.getElementsByTagName("id")[0].firstChild.nodeValue.substring(9);
53-
this.entryAttributes = {};
54-
this.parseProperties("propertyId",
55-
function (stringValue) {
56-
return stringValue;
57-
}
58-
);
59-
this.parseProperties("propertyString",
60-
function (stringValue) {
61-
return stringValue;
62-
}
63-
);
64-
this.parseProperties("propertyInteger", parseInt);
65-
66-
this.parseProperties("propertyBoolean",
67-
function (stringValue) {
68-
return stringValue === 'true';
69-
}
70-
);
71-
this.parseProperties("propertyDateTime", cmis.parseDate);
72-
},
73-
74-
parseProperties: function (tagName, converter) {
75-
var propertyStrings =
76-
browser.getElementsByTagName(this.entry, "cmis", tagName);
77-
for (var i = 0; i < propertyStrings.length; i++) {
78-
var propertyString = propertyStrings[i];
79-
var cmisAttributeName =
80-
propertyString.getAttribute("propertyDefinitionId");
81-
var entryAttribute = {
82-
tagName: tagName,
83-
values: [],
84-
value: function () {
85-
return (this.values.length > 0) ? this.values[0] : null
86-
}
87-
};
88-
this.entryAttributes[cmisAttributeName] = entryAttribute;
89-
var valueNode = browser.getElementsByTagName(propertyString, "cmis", "value");
90-
if (valueNode) {
91-
array.forEach(valueNode, function (current) {
92-
var cmisAttributeValue = null;
93-
try {
94-
var nodeValue = current.firstChild.nodeValue;
95-
cmisAttributeValue = converter(nodeValue);
96-
} catch (e) {
97-
cmisAttributeValue = null;
98-
}
99-
entryAttribute.values.push(cmisAttributeValue);
100-
});
101-
}
102-
}
103-
},
104-
10545
composeLines: function () {
106-
if (this.entryAttributes["cmis:baseTypeId"].value() === "cmis:document") {
46+
if (this.entry.getAttributeValue("cmis:baseTypeId") === "cmis:document") {
10747
this.previewUrl = lang.replace(
10848
"{proxyUri}api/node/workspace/SpacesStore/{entryId}/content/thumbnails/doclib?c=queue&ph=true&lastModified=1",
10949
{
11050
proxyUri: Alfresco.constants.PROXY_URI,
111-
entryId: this.entryId
51+
entryId: this.entry.id
11252
}
11353
);
11454
} else {
@@ -123,37 +63,37 @@ define([
12363
"{proxyUri}api/node/content/workspace/SpacesStore/{entryId}/{filename}?a=true",
12464
{
12565
proxyUri: Alfresco.constants.PROXY_URI,
126-
entryId: this.entryId,
127-
filename: encodeURIComponent(this.entryAttributes["cmis:name"].value())
66+
entryId: this.entry.id,
67+
filename: encodeURIComponent(this.entry.getAttributeValue("cmis:name"))
12868
}
12969
);
130-
this.escapedLine1 = this.encodeHTML(this.entryAttributes["cmis:name"].value());
70+
this.escapedLine1 = this.encodeHTML(this.entry.getAttributeValue("cmis:name"));
13171
if (!this.escapedLine1) {
13272
this.escapedLine1 = "";
13373
}
134-
this.escapedLine2 = this.encodeHTML(this.entryAttributes["cm:title"].value());
74+
this.escapedLine2 = this.encodeHTML(this.entry.getAttributeValue("cm:title"));
13575
if (!this.escapedLine2) {
13676
this.escapedLine2 = "";
13777
}
13878
var line3 = this.message(
13979
"modified.on.by",
14080
{
141-
date: locale.format(this.entryAttributes["cmis:lastModificationDate"].value(), {
81+
date: locale.format(this.entry.getAttributeValue("cmis:lastModificationDate"), {
14282
formatLength: "medium",
14383
locale: Alfresco.constants.JS_LOCALE.substring(0, 2)
14484
}),
145-
user: this.entryAttributes["cmis:lastModifiedBy"].value()
85+
user: this.entry.getAttributeValue("cmis:lastModifiedBy")
14686
}
14787
);
14888
this.escapedLine3 = this.encodeHTML(line3);
14989
if (!this.escapedLine3) {
15090
this.escapedLine3 = "";
15191
}
152-
this.escapedLine4 = this.encodeHTML(this.entryAttributes["cm:description"].value());
92+
this.escapedLine4 = this.encodeHTML(this.entry.getAttributeValue("cm:description"));
15393
if (!this.escapedLine4) {
15494
this.escapedLine4 = "";
15595
}
156-
var versionLabel = this.entryAttributes["cmis:versionLabel"].value();
96+
var versionLabel = this.entry.getAttributeValue("cmis:versionLabel");
15797
if ("0.0" === versionLabel) {
15898
versionLabel = "1.0";
15999
}
@@ -165,7 +105,7 @@ define([
165105
this.downloadLabel = this.message(
166106
"download.size",
167107
{
168-
size: this.getHumanSize(this.entryAttributes["cmis:contentStreamLength"].value())
108+
size: this.getHumanSize(this.entry.getAttributeValue("cmis:contentStreamLength"))
169109
}
170110
);
171111
},
@@ -185,7 +125,7 @@ define([
185125
"Document approved",
186126
"This is just a stub action. " +
187127
"To provide a real implementation you should customize " +
188-
"Item.approveAction()",
128+
"Item.approveAction()",
189129
true
190130
);
191131
},
@@ -195,7 +135,7 @@ define([
195135
"Document rejected",
196136
"This is just a stub action. " +
197137
"To provide a real implementation you should customize " +
198-
"Item.rejectAction()",
138+
"Item.rejectAction()",
199139
true
200140
);
201141
},

0 commit comments

Comments
 (0)