Skip to content

Commit

Permalink
Issue 13440 drawed templates (#13441)
Browse files Browse the repository at this point in the history
* Fix TreeTransformer for Oracle. (#13439)

* #13440 draw your templates
  • Loading branch information
wezell authored Jan 18, 2018
1 parent 0b9c9f5 commit 91eee49
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ final public boolean render(InternalContextAdapter context, Writer writer, Node

try{
String templatePath = this.resolveTemplatePath(context, writer, params, arguments);
if(null ==templatePath) {
throw new ResourceNotFoundException("null template");
}
Template t = loadTemplate(context, templatePath);
return this.renderTemplate(context, writer, t, templatePath);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import com.dotmarketing.beans.Identifier;
import com.dotmarketing.beans.Tree;
import com.dotmarketing.beans.transform.IdentifierTransformer;
import com.dotmarketing.beans.transform.OracleTreeTransformer;
import com.dotmarketing.beans.transform.TreeTransformer;
import com.dotmarketing.db.DbConnectionFactory;
import com.dotmarketing.portlets.containers.model.Container;
import com.dotmarketing.portlets.containers.transform.ContainerTransformer;
import com.dotmarketing.portlets.contentlet.model.Contentlet;
Expand Down Expand Up @@ -147,6 +149,6 @@ public static IdentifierTransformer createIdentifierTransformer(
public static TreeTransformer createTreeTransformer(
List<Map<String, Object>> initList) {

return new TreeTransformer(initList);
return DbConnectionFactory.isOracle()?new OracleTreeTransformer(initList):new TreeTransformer(initList);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.dotmarketing.beans.transform;

import com.dotmarketing.beans.Tree;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

public class OracleTreeTransformer extends TreeTransformer {

public OracleTreeTransformer(List<Map<String, Object>> list) {
super(list);
}

@Override
Tree toTree(Map<String, Object> map) {
Tree tree=new Tree();
tree.setParent((String)map.getOrDefault("parent", null));
tree.setChild((String)map.getOrDefault("child", null));
tree.setRelationType((String)map.getOrDefault("relation_type", null));
tree.setTreeOrder(((BigDecimal)map.getOrDefault("tree_order", 0)).intValue());

return tree;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public Tree findFirst() {
return this.asList().stream().findFirst().orElse(new Tree());
}

private Tree toTree (Map<String, Object> map){
Tree toTree (Map<String, Object> map){

Tree tree=new Tree();
tree.setParent((String)map.getOrDefault("parent", null));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.dotmarketing.util.Logger;
import com.dotmarketing.util.PaginatedArrayList;
import com.dotmarketing.util.RegEX;
import com.dotmarketing.util.UUIDGenerator;
import com.dotmarketing.util.UtilMethods;

import java.io.IOException;
Expand Down Expand Up @@ -107,19 +108,30 @@ public void delete(Template template) throws DotDataException {
}

public void save(Template template) throws DotDataException {
if(!UtilMethods.isSet(template.getIdentifier())){
throw new DotStateException("Cannot save a template without an Identifier");
}
HibernateUtil.save(template);



save(template, UUIDGenerator.generateUuid());

new TemplateLoader().invalidate(template);

}

public void save(Template template, String existingId) throws DotDataException {
if(!UtilMethods.isSet(template.getIdentifier())){
throw new DotStateException("Cannot save a tempalte without an Identifier");
}

if(UtilMethods.isSet(template.getDrawedBody())) {
template.setDrawed(true);
}else {
template.setDrawedBody((String)null);
template.setDrawed(false);
}





HibernateUtil.saveWithPrimaryKey(template, existingId);
templateCache.add(template.getInode(), template);
new TemplateLoader().invalidate(template);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class Template extends WebAsset implements Serializable, Comparable {
private String image;

// *********************** BEGIN GRAZIANO issue-12-dnd-template
private Boolean drawed;
private Boolean drawed=false;

private String drawedBody;

Expand Down Expand Up @@ -195,18 +195,15 @@ public void setHeader(String header) {
* @return
*/
public Boolean isDrawed() {
return this.drawed;
return (this.drawed==null) ? UtilMethods.isSet(drawedBody) : this.drawed;
}

/**
* Sets the boolean for drawed template
* @param drawed
*/
public void setDrawed(Boolean drawed) {
if(null!=drawed)
this.drawed = drawed;
else
this.drawed = false;
this.drawed = (null!=drawed) ? drawed : false;
}

public String getDrawedBody() {
Expand Down

0 comments on commit 91eee49

Please sign in to comment.