Skip to content

Commit

Permalink
Merge pull request #19 from openviglet/0.3.2
Browse files Browse the repository at this point in the history
0.3.2
  • Loading branch information
alegauss authored Aug 28, 2018
2 parents 0d9b023 + 1c3ec14 commit 611d525
Show file tree
Hide file tree
Showing 26 changed files with 479 additions and 93 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
* InContext Editing using Float Menu to Regions
* Site Form: Create Forms into Site and save as Posts into Shiohara CMS
* Combo Box Field Type
* Hidden Field Type
* Form Configuration Field Type

#### IMPROVEMENTS
* Spring Boot 2.0.4 and Gradle 4.9
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package com.viglet.shiohara.component;
package com.viglet.shiohara.component.form;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.security.web.csrf.CsrfToken;
Expand Down Expand Up @@ -39,7 +43,7 @@ public class ShFormComponent {
public String byPostType(String shPostTypeName, String shObjectId, HttpServletRequest request)
throws InstantiationException, IllegalAccessException, ClassNotFoundException {
final Context ctx = new Context();

ShFormConfiguration shFormConfiguration = null;
ShObject shObject = shObjectRepository.findById(shObjectId).get();
ShPostType shPostType = shPostTypeRepository.findByName(shPostTypeName);
CsrfToken csrf = (CsrfToken) request.getAttribute(CsrfToken.class.getName());
Expand All @@ -60,6 +64,11 @@ public int compare(ShPostTypeAttr o1, ShPostTypeAttr o2) {
ShWidgetImplementation object = (ShWidgetImplementation) Class.forName(className).newInstance();
applicationContext.getAutowireCapableBeanFactory().autowireBean(object);
fields.add(object.render(shPostTypeAttr, shObject));

if (shPostTypeAttr.getShWidget().getName().equals(ShSystemWidget.FORM_CONFIGURATION)) {
JSONObject formConfiguration= new JSONObject(shPostTypeAttr.getWidgetSettings());
shFormConfiguration = new ShFormConfiguration(formConfiguration);
}
}

String token = null;
Expand All @@ -71,6 +80,7 @@ public int compare(ShPostTypeAttr o1, ShPostTypeAttr o2) {
ctx.setVariable("shPostType", shPostType);
ctx.setVariable("shPostTypeAttrs", shPostType.getShPostTypeAttrs());
ctx.setVariable("fields", fields);
ctx.setVariable("shFormConfiguration", shFormConfiguration);

return templateEngine.process("form", ctx);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.viglet.shiohara.component.form;

import java.util.UUID;

import org.apache.commons.lang3.StringUtils;
import org.json.JSONObject;
import org.springframework.http.HttpMethod;

public class ShFormConfiguration {

private HttpMethod method;
private UUID pageLayout;
private boolean createPost;
private UUID folder;

public ShFormConfiguration(JSONObject setting) {
super();
this.setMethod(HttpMethod.valueOf(setting.getString("method")));
this.setPageLayout(UUID.fromString(setting.getString("pageLayout")));
this.setCreatePost(setting.getInt("createPost") == 1 ? true : false);
this.setFolder(
StringUtils.isNotBlank(setting.getString("folder")) ? UUID.fromString(setting.getString("folder"))
: null);
}

public HttpMethod getMethod() {
return method;
}

public void setMethod(HttpMethod method) {
this.method = method;
}

public UUID getPageLayout() {
return pageLayout;
}

public void setPageLayout(UUID pageLayout) {
this.pageLayout = pageLayout;
}

public boolean isCreatePost() {
return createPost;
}

public void setCreatePost(boolean createPost) {
this.createPost = createPost;
}

public UUID getFolder() {
return folder;
}

public void setFolder(UUID folder) {
this.folder = folder;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,16 @@ public void createDefaultRows() {
shWidget.setType("TEXT,TEXTAREA");

shWidgetRepository.save(shWidget);

shWidget = new ShWidget();
shWidget.setName(ShSystemWidget.FORM_CONFIGURATION);
shWidget.setDescription("Form Configuraion Widget");
shWidget.setClassName("com.viglet.shiohara.widget.ShFormConfigurationWidget");
shWidget.setImplementationCode("template/widget/form/form-configuration.html");
shWidget.setSettingPath("template/widget/form/setting/form-configuration-setting.html");
shWidget.setType("TEXT,TEXTAREA");

shWidgetRepository.save(shWidget);
}

}
Expand Down
98 changes: 9 additions & 89 deletions src/main/java/com/viglet/shiohara/sites/ShSitesContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@

import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.activation.MimetypesFileTypeMap;
import javax.annotation.Resource;
Expand All @@ -26,41 +22,28 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.view.RedirectView;

import com.viglet.shiohara.api.post.ShPostAPI;
import com.viglet.shiohara.cache.ShCacheManager;
import com.viglet.shiohara.cache.ShCachedObject;
import com.viglet.shiohara.persistence.model.folder.ShFolder;
import com.viglet.shiohara.persistence.model.post.ShPost;
import com.viglet.shiohara.persistence.model.post.ShPostAttr;
import com.viglet.shiohara.persistence.model.post.type.ShPostType;
import com.viglet.shiohara.persistence.model.post.type.ShPostTypeAttr;
import com.viglet.shiohara.persistence.model.site.ShSite;
import com.viglet.shiohara.persistence.repository.folder.ShFolderRepository;
import com.viglet.shiohara.persistence.repository.post.ShPostRepository;
import com.viglet.shiohara.persistence.repository.post.type.ShPostTypeAttrRepository;
import com.viglet.shiohara.persistence.repository.post.type.ShPostTypeRepository;
import com.viglet.shiohara.post.type.ShSystemPostType;
import com.viglet.shiohara.post.type.ShSystemPostTypeAttr;
import com.viglet.shiohara.utils.ShFolderUtils;
import com.viglet.shiohara.utils.ShFormUtils;
import com.viglet.shiohara.utils.ShPostUtils;
import com.viglet.shiohara.utils.ShSiteUtils;
import com.viglet.shiohara.utils.ShStaticFileUtils;
import com.viglet.shiohara.widget.ShWidgetImplementation;
import com.viglet.shiohara.widget.ecommerce.ShPaymentWidget;

@Controller
public class ShSitesContext {
@Resource
private ApplicationContext applicationContext;
@Autowired
private ShPostTypeRepository shPostTypeRepository;
@Autowired
private ShPostTypeAttrRepository shPostTypeAttrRepository;
@Autowired
private ShPostRepository shPostRepository;
@Autowired
private ShFolderRepository shFolderRepository;
@Autowired
private ShFolderUtils shFolderUtils;
@Autowired
private ShPostUtils shPostUtils;
Expand All @@ -69,93 +52,30 @@ public class ShSitesContext {
@Autowired
private ShSitesContextComponent shSitesContextComponent;
@Autowired
private ShPostAPI shPostAPI;
@Autowired
private ShStaticFileUtils shStaticFileUtils;
@Autowired
private ShSitesContextURL shSitesContextURL;
@Autowired
private ShPaymentWidget shPaymentWidget;
private ShFormUtils shFormUtils;

@PostMapping("/sites/**")
private RedirectView sitesPostForm(HttpServletRequest request, HttpServletResponse response) throws IOException,
ScriptException, InstantiationException, IllegalAccessException, ClassNotFoundException {
shSitesContextURL.init(request, response);

this.siteContextPost(shSitesContextURL, request, response);
this.siteContextPost(shSitesContextURL);
RedirectView redirectView = new RedirectView(
new String((request.getRequestURL() + "/success").getBytes("UTF-8"), "ISO-8859-1"));
redirectView.setHttp10Compatible(false);
return redirectView;
}

public byte[] siteContextPost(ShSitesContextURL shSitesContextURL, HttpServletRequest request,
HttpServletResponse response) throws IOException, ScriptException, InstantiationException,
IllegalAccessException, ClassNotFoundException {
ShPost shPost = null;
if (request.getParameter("__sh-post-type-attr-__FORM_FOLDER_ID") != null
|| shSitesContextURL.getShObject() instanceof ShFolder
|| (shSitesContextURL.getShObject() instanceof ShPost && ((ShPost) shSitesContextURL.getShObject())
.getShPostType().getName().equals(ShSystemPostType.FOLDER_INDEX))) {
ShFolder shFolder = null;

if (request.getParameter("__sh-post-type-attr-__FORM_FOLDER_ID") != null) {
shFolder = shFolderRepository.findById(request.getParameter("__sh-post-type-attr-__FORM_FOLDER_ID"))
.get();
} else {
if (shSitesContextURL.getShObject() instanceof ShFolder) {
shFolder = (ShFolder) shSitesContextURL.getShObject();
} else {
shFolder = ((ShPost) shSitesContextURL.getShObject()).getShFolder();
}
}
String shPostTypeName = request.getParameter("__sh-post-type");
ShPostType shPostType = shPostTypeRepository.findByName(shPostTypeName);

Enumeration<String> parameters = request.getParameterNames();
if (shPostTypeName != null) {
shPost = new ShPost();
shPost.setDate(new Date());
shPost.setOwner("anonymous");
shPost.setShFolder(shFolder);

shPost.setShPostType(shPostType);
Set<ShPostAttr> shPostAttrs = new HashSet<ShPostAttr>();
while (parameters.hasMoreElements()) {
String param = parameters.nextElement();
String paramValue = request.getParameter(param);

if (param.startsWith("__sh-post-type-attr-")
&& !param.equals("__sh-post-type-attr-__FORM_FOLDER_ID")) {
String attribute = param.replaceFirst("__sh-post-type-attr-", "");

ShPostTypeAttr shPostTypeAttr = shPostTypeAttrRepository.findByShPostTypeAndName(shPostType,
attribute);

String className = shPostTypeAttr.getShWidget().getClassName();
ShWidgetImplementation object = (ShWidgetImplementation) Class.forName(className).newInstance();
applicationContext.getAutowireCapableBeanFactory().autowireBean(object);

@SuppressWarnings("unused")
boolean attrStatus = object.validateForm(request, shPostTypeAttr);
// TODO: Create validation Form logic

ShPostAttr shPostAttr = new ShPostAttr();
shPostAttr.setShPost(shPost);
shPostAttr.setShPostTypeAttr(shPostTypeAttr);
shPostAttr.setStrValue(paramValue);

shPostAttrs.add(shPostAttr);
}

}
shPost.setShPostAttrs(shPostAttrs);
shPostAPI.postSave(shPost);
}
}

shPaymentWidget.postRender(shPost, shSitesContextURL);
this.sitesFullGeneric(request, response);
public byte[] siteContextPost(ShSitesContextURL shSitesContextURL) throws IOException, ScriptException,
InstantiationException, IllegalAccessException, ClassNotFoundException {

shFormUtils.execute(shSitesContextURL);

this.sitesFullGeneric(shSitesContextURL.getRequest(), shSitesContextURL.getResponse());

return null;
}
Expand Down
Loading

0 comments on commit 611d525

Please sign in to comment.