Skip to content

Commit

Permalink
add access to several kind of documents, fix bug with unfind template…
Browse files Browse the repository at this point in the history
…, fix bug with multi-select possibility in category
  • Loading branch information
OlegDokuka committed Jul 10, 2015
1 parent 089fd75 commit e7782dc
Show file tree
Hide file tree
Showing 27 changed files with 744 additions and 242 deletions.
6 changes: 3 additions & 3 deletions pom-ant.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@

<setsystemproperty name="org.apache.commons.logging.Log" value="org.apache.commons.logging.impl.NoOpLog"/>

<target name="changes">
<!--<target name="changes">
<xslt in="docs/changes.xml" style="docs/changes.xsl" out="docs/CHANGES.HTML"/>
</target>
</target>-->

<target name="process-webapp-sources" depends="init,changes"
<target name="process-webapp-sources" depends="init"
description="Translates and copies the webapp sources to webapp.">

<property name="texttemplates" value="${webinf.templates.dir}/text"/>
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/imcode/imcms/flow/PageFlow.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.imcode.imcms.flow;

import imcode.server.document.DocumentDomainObject;
import imcode.util.HttpSessionAttribute;
import imcode.util.HttpSessionUtils;

import java.io.IOException;
import java.io.Serializable;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.Serializable;

public abstract class PageFlow implements Serializable, HttpSessionAttribute {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
public interface FileDocFileRepository extends JpaRepository<FileDocFile, Integer> {

@Modifying
@Query("DELETE FROM FileDocFile f WHERE f.version.docId = ?1 AND f.version.no = ?2")
@Query("DELETE FROM FileDocFile f WHERE f.documentId IN (SELECT v FROM Version v WHERE v.no = ?2 AND v.docId = ?1)")
void deleteByDocIdAndVersionNo(int docId, int versionNo);

@Query("SELECT f FROM FileDocFile f WHERE f.version.docId = ?1 AND f.version.no = ?2 ORDER BY f.defaultFileId DESC, f.fileId")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ public abstract class VersionedContent {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;

@Column(name = "doc_id", unique = true, nullable = false, insertable = false, updatable = false)
private Integer documentId;

@NotNull
@ManyToOne
@JoinColumns({
Expand All @@ -35,4 +38,8 @@ public Version getVersion() {
public void setVersion(Version contentVersion) {
this.version = contentVersion;
}

public Integer getDocumentId() {
return documentId;
}
}
57 changes: 38 additions & 19 deletions src/main/java/com/imcode/imcms/servlet/admin/AdminDoc.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
package com.imcode.imcms.servlet.admin;

import com.imcode.imcms.flow.*;
import com.imcode.imcms.api.ContentManagementSystem;
import com.imcode.imcms.api.Document;
import com.imcode.imcms.flow.ChangeDocDefaultVersionPageFlow;
import com.imcode.imcms.flow.DispatchCommand;
import com.imcode.imcms.flow.PageFlow;
import com.imcode.imcms.mapping.DocumentMapper;
import com.imcode.imcms.servlet.GetDoc;
import imcode.server.DocumentRequest;
import imcode.server.Imcms;
import imcode.server.ImcmsConstants;
Expand All @@ -14,21 +20,17 @@
import imcode.util.Html;
import imcode.util.Utility;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Stack;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.imcode.imcms.mapping.DocumentMapper;
import com.imcode.imcms.servlet.GetDoc;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Stack;

/**
* Handles admin panel commands.
Expand All @@ -37,16 +39,33 @@ public class AdminDoc extends HttpServlet {

private static class EditDocPageFlow extends PageFlow {

protected DocumentDomainObject document;

// todo: editor tag arg: perms/info/profile/etc
private EditDocPageFlow() {
private EditDocPageFlow(DocumentDomainObject document) {
super(null);

this.document = document;
}

@Override
public void dispatch(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
String docAdminUrl = request.getContextPath() + "/imcms/docadmin?meta_id=" + request.getParameter("meta_id");
//String docAdminUrl = request.getContextPath() + "/imcms/docadmin?meta_id=" + request.getParameter("meta_id");
DocumentRequest documentRequest = new DocumentRequest(Imcms.getServices(), Imcms.getUser(), document, null, request, response);
ParserParameters parserParameters = new ParserParameters(documentRequest);

parserParameters.setFlags(56568);

ParserParameters.putInRequest(parserParameters);

ContentManagementSystem cms = ContentManagementSystem.fromRequest(request);
Document document = cms.getDocumentService().getDocument(this.document.getId());

request.setAttribute("document", document);
request.setAttribute("user", cms.getCurrentUser());


response.sendRedirect(docAdminUrl);
request.getRequestDispatcher("/WEB-INF/jsp/admin/edit_document.jsp").forward(request, response);
}

@Override
Expand Down Expand Up @@ -77,7 +96,7 @@ public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOExce

/**
* Creates a document page flow and dispatches request to that flow.
* <p>
* <p/>
* If flow can not be created or an user is not allowed to edit a document adminDoc is called.
*/
public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
Expand Down Expand Up @@ -117,15 +136,15 @@ private PageFlow createFlow(HttpServletRequest req, DocumentDomainObject documen

PageFlow pageFlow = null;
if (ImcmsConstants.DISPATCH_FLAG__DOCINFO_PAGE == flags && user.canEditDocumentInformationFor(document)) {
pageFlow = new EditDocPageFlow();
pageFlow = new EditDocPageFlow(document);
} else if (ImcmsConstants.DISPATCH_FLAG__DOCUMENT_PERMISSIONS_PAGE == flags && user.canEditPermissionsFor(document)) {
pageFlow = new EditDocPageFlow();
pageFlow = new EditDocPageFlow(document);
} else if (document instanceof HtmlDocumentDomainObject && ImcmsConstants.DISPATCH_FLAG__EDIT_HTML_DOCUMENT == flags) {
pageFlow = new EditDocPageFlow();
pageFlow = new EditDocPageFlow(document);
} else if (document instanceof UrlDocumentDomainObject && ImcmsConstants.DISPATCH_FLAG__EDIT_URL_DOCUMENT == flags) {
pageFlow = new EditDocPageFlow();
pageFlow = new EditDocPageFlow(document);
} else if (document instanceof FileDocumentDomainObject && ImcmsConstants.DISPATCH_FLAG__EDIT_FILE_DOCUMENT == flags) {
pageFlow = new EditDocPageFlow();
pageFlow = new EditDocPageFlow(document);
} else if (ImcmsConstants.DISPATCH_FLAG__PUBLISH == flags) {
pageFlow = new ChangeDocDefaultVersionPageFlow(document, returnCommand, new DocumentMapper.MakeDocumentVersionCommand(), user);
} else if (ImcmsConstants.DISPATCH_FLAG__SET_DEFAULT_VERSION == flags) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.io.IOException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand All @@ -28,9 +29,12 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se
.collect(
Collectors.toMap(
CategoryTypeDomainObject::getName,
val -> Stream.of(categoryMapper.getAllCategoriesOfType(val))
.map(CategoryDomainObject::getName)
.collect(Collectors.toList())
val -> new Object() {
public List<String> items = Stream.of(categoryMapper.getAllCategoriesOfType(val))
.map(CategoryDomainObject::getName)
.collect(Collectors.toList());
public boolean isMultiple = val.isMultiselect();
}
)
)
);
Expand Down

0 comments on commit e7782dc

Please sign in to comment.