Skip to content

Commit

Permalink
Merge 8ef15ed into 8328ea2
Browse files Browse the repository at this point in the history
  • Loading branch information
chripalombella committed Jul 9, 2019
2 parents 8328ea2 + 8ef15ed commit a9c382f
Show file tree
Hide file tree
Showing 15 changed files with 446 additions and 46 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ XML structure:
<dynamic-element name="nestedText" index="0" type="text" index-type="keyword">
<dynamic-content language-id="en_US"><![CDATA[Nested Text :)]]></dynamic-content>
</dynamic-element>
<dynamic-content language-id="en_US"><![CDATA[/documents/20281/0/welcome_community/d83a745d-8624-44c0-baad-3c7d05e3b2dc?t=1439123090000]]></dynamic-content>
<dynamic-content language-id="en_US"><![CDATA[{"classPK":"46245","groupId":"20127","title":"Footer.png","type":"document","uuid":"223fac3c-abe2-e24a-1097-31cd1ce030156"}]]></dynamic-content>
</dynamic-element>
</root>
```
Expand Down Expand Up @@ -233,7 +233,7 @@ public class NestedBar extends ConvertibleJournalArticle {
private String myText;

@JournalArticleField(base = true)
private String documentsAndMedia;
private DDMDocumentAndMedia documentsAndMedia;

public Boolean getMyBoolean() {
return myBoolean;
Expand All @@ -251,17 +251,17 @@ public class NestedBar extends ConvertibleJournalArticle {
this.myText = myText;
}

public String getDocumentsAndMedia() {
public DDMDocumentAndMedia getDocumentsAndMedia() {
return documentsAndMedia;
}

public void setDocumentsAndMedia(String documentsAndMedia) {
public void setDocumentsAndMedia(DDMDocumentAndMedia documentsAndMedia) {
this.documentsAndMedia = documentsAndMedia;
}

@Override
public String toString() {
return "[myBoolean = " + myBoolean + ", myText = " + myText + ", documentsAndMedia = " + documentsAndMedia + "]";
return "[myBoolean = " + myBoolean + ", myText = " + myText + "]";
}
}
```
Expand All @@ -274,7 +274,7 @@ JournalArticle journalArticle = JournalArticleLocalServiceUtil.getArticle(id);
NestedFoo nestedFoo = new NestedFoo();
nestedFoo.fromJournalArticle(journalArticle);
NestedBar nestedBar = nestedFoo.getNestedBar();
System.out.println(nestedBar); //[myBoolean = true, myText = Nested Text :), documentsAndMedia = /documents/20281/0/welcome_community/d83a745d-8624-44c0-baad-3c7d05e3b2dc?t=1439123090000]
System.out.println(nestedBar); //[myBoolean = true, myText = Nested Text :)]
```


Expand Down
10 changes: 7 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -176,21 +176,25 @@
<artifactId>jsoup</artifactId>
<version>1.8.3</version>
</dependency>

<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
</dependency>
<dependency>
<groupId>com.liferay</groupId>
<artifactId>com.liferay.journal.api</artifactId>
<version>2.12.4</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.liferay.portal</groupId>
<artifactId>com.liferay.portal.kernel</artifactId>
<version>2.61.1</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.liferay</groupId>
<artifactId>com.liferay.dynamic.data.mapping.api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.davidepastore.liferay.converter;

import java.io.FileNotFoundException;
import java.lang.reflect.Field;
import java.lang.reflect.ParameterizedType;
import java.math.BigDecimal;
Expand All @@ -14,7 +15,13 @@
import org.jsoup.select.Elements;

import com.github.davidepastore.liferay.annotation.JournalArticleField;
import com.github.davidepastore.liferay.model.DDMDocumentAndMedia;
import com.github.davidepastore.liferay.model.DDMGeolocation;
import com.github.davidepastore.liferay.model.DDMImage;
import com.github.davidepastore.liferay.util.JsonUtil;
import com.github.davidepastore.liferay.util.SimpleLocaleUtil;
import com.google.gson.JsonIOException;
import com.google.gson.JsonSyntaxException;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.journal.model.JournalArticle;
Expand Down Expand Up @@ -63,8 +70,12 @@ public void fromJournalArticle(JournalArticle journalArticle, Locale locale) thr
* @throws IllegalAccessException
* @throws IllegalArgumentException
* @throws InstantiationException
* @throws FileNotFoundException
* @throws IndexOutOfBoundsException
* @throws JsonIOException
* @throws JsonSyntaxException
*/
protected void setValueFromElements(Elements elements, Object object, String title) throws IllegalArgumentException, IllegalAccessException, InstantiationException{
protected void setValueFromElements(Elements elements, Object object, String title) throws IllegalArgumentException, IllegalAccessException, InstantiationException, JsonSyntaxException, JsonIOException, IndexOutOfBoundsException, FileNotFoundException{
List<String> names = getDynamicElementNames(elements);
Object value = null;
for (String name : names) {
Expand Down Expand Up @@ -123,8 +134,11 @@ protected void setValueFromElements(Elements elements, Object object, String tit
* @return Returns the object with the found value (it also handles nested properties).
* @throws InstantiationException
* @throws IllegalAccessException
* @throws FileNotFoundException
* @throws JsonIOException
* @throws JsonSyntaxException
*/
protected Object getObjectValue(Element element, Object object, String title) throws InstantiationException, IllegalAccessException, NumberFormatException, IndexOutOfBoundsException {
protected Object getObjectValue(Element element, Object object, String title) throws InstantiationException, IllegalAccessException, NumberFormatException, IndexOutOfBoundsException, JsonSyntaxException, JsonIOException, FileNotFoundException {
Object value = null;
String type = element.attr("type");
String stringValue = element.text();
Expand Down Expand Up @@ -162,9 +176,11 @@ protected Object getObjectValue(Element element, Object object, String title) th
} else if(type.equals("ddm-decimal")){
value = new Double(stringValue);
} else if(type.equals("image")){
value = stringValue;
DDMImage ddmImage = JsonUtil.getDDMImage(stringValue);
value = ddmImage;
} else if(type.equals("document_library")){
value = stringValue;
DDMDocumentAndMedia ddmDocumentAndMedia = JsonUtil.getDDMDocumentAndMedia(stringValue);
value = ddmDocumentAndMedia;
} else if(type.equals("ddm-integer")){
value = Integer.parseInt(stringValue);
} else if(type.equals("link_to_layout")){
Expand All @@ -191,7 +207,8 @@ protected Object getObjectValue(Element element, Object object, String title) th
} else if(type.equals("text_area")){
value = stringValue;
} else if(type.equals("ddm-geolocation")) {
value = stringValue;
DDMGeolocation ddmGeolocation = JsonUtil.getDDMGeolocation(stringValue);
value = ddmGeolocation;
}

return value;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package com.github.davidepastore.liferay.model;

import com.liferay.portal.kernel.util.Validator;

/**
* @author Christian Palombella
*
*/
public class DDMDocumentAndMedia {

private String classPK;
private String groupId;
private String title;
private String type;
private String uuid;

public DDMDocumentAndMedia() {
super();
}

/**
* @param classPK
* @param groupId
* @param title
* @param type
* @param uuid
*/
public DDMDocumentAndMedia(String classPK, String groupId, String title, String type, String uuid) {
super();
this.classPK = classPK;
this.groupId = groupId;
this.title = title;
this.type = type;
this.uuid = uuid;
}

public String getClassPK() {
return classPK;
}

public void setClassPK(String classPK) {
this.classPK = classPK;
}

public String getGroupId() {
return groupId;
}

public void setGroupId(String groupId) {
this.groupId = groupId;
}

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}

public String getUuid() {
return uuid;
}

public void setUuid(String uuid) {
this.uuid = uuid;
}

public String getUrl() {
if(Validator.isNotNull(this.groupId) && Validator.isNotNull(this.classPK) && Validator.isNotNull(this.title) && Validator.isNotNull(this.uuid))
return "/documents/" + this.groupId + "/" + this.classPK + "/" + this.title + "/" + this.uuid;
else return "";
}

/**
* Check if the object are equals.
*/
@Override
public boolean equals(Object obj) {
return obj instanceof DDMDocumentAndMedia
&& groupId.equals(((DDMDocumentAndMedia) obj)
.getGroupId())
&& classPK.equals(((DDMDocumentAndMedia) obj)
.getClassPK())
&& uuid.equals(((DDMDocumentAndMedia) obj)
.getUuid())
&& type.equals(((DDMDocumentAndMedia) obj)
.getType())
&& title.equals(((DDMDocumentAndMedia) obj)
.getTitle());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.github.davidepastore.liferay.model;

/**
*
* @author Christian Palombella
*
*/
public class DDMGeolocation {

private Double latitude;
private Double longitude;

public DDMGeolocation() {
super();
}

public DDMGeolocation(Double latitude, Double longitude) {
super();
this.latitude = latitude;
this.longitude = longitude;
}

public Double getLatitude() {
return latitude;
}

public void setLatitude(Double latitude) {
this.latitude = latitude;
}

public Double getLongitude() {
return longitude;
}

public void setLongitude(Double longitude) {
this.longitude = longitude;
}

}

0 comments on commit a9c382f

Please sign in to comment.