Skip to content

Commit

Permalink
Fixes for #15, added support for #22, started with #23
Browse files Browse the repository at this point in the history
  • Loading branch information
mukil committed Oct 2, 2020
1 parent 51eb7bd commit 8b2ce96
Show file tree
Hide file tree
Showing 19 changed files with 526 additions and 94 deletions.
38 changes: 23 additions & 15 deletions src/main/java/de/mikromedia/webpages/WebpagePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -231,18 +231,20 @@ public Viewable getWebpage(@PathParam("pageWebAlias") String webAlias) {
dmx.fireEvent(CUSTOM_ROOT_RESOURCE_REQUESTED, context(), website, pageAlias, uriInfo);
return getWebsiteTemplate(website, pageAlias);
}
// 3) if no website frontpage exist for that prefix, we continue with our standard website for page preparation
// 3) if no website (frontpage) exist for that prefix, we continue with our standard website for page preparation
website = getStandardWebsite();
dmx.fireEvent(WEBPAGE_REQUESTED, context(), pageAlias, STANDARD_WEBSITE_PREFIX);
log.info("Preparing STANDARD FRONTPAGE view data in dmx-webpages plugin...");
prepareWebsiteViewData(website, webAlias);
// 4) check for existing pageAlias and fetch and return that webpage
Webpage webpage = getWebsitesWebpage(website, pageAlias);
if (webpage != null) {
log.info("Preparing WEBPAGE view data \""+webpage.getTitle().toString()+"\" ...");
prepareGenericViewData(SIMPLE_PAGE_TEMPLATE_NAME, STANDARD_WEBSITE_PREFIX, pageAlias);
Topic htmlTemplate = webpage.getHTMLTemplate();
String templateFilename = getTemplateFileName(htmlTemplate);
log.info("Preparing WEBPAGE view data \""+webpage.getTitle().toString()+"\" for template=\"" + templateFilename + "\"");
prepareGenericViewData(templateFilename, STANDARD_WEBSITE_PREFIX, pageAlias);
preparePageViewData(webpage);
return getWebpageTemplate(webpage);
return getWebpageTemplate(webpage, templateFilename);
}
log.fine("=> /" + pageAlias + " webpage for standard website not found.");
// 5) Check for redirects related to "standard" webpage
Expand All @@ -267,19 +269,20 @@ public Viewable getWebpage(@PathParam("pageWebAlias") String webAlias) {
public Viewable getWebsitePage(@PathParam("site") String sitePrefix, @PathParam("pageWebAlias") String webAlias) {
String pageAlias = webAlias.trim();
String location = "/" + sitePrefix + "/" + webAlias;
// 1) Fetch some website topic
// 1) Query for website topic
Topic usersWebsite = getWebsiteByPrefix(sitePrefix);
if (usersWebsite != null) {
prepareGenericViewData(SIMPLE_PAGE_TEMPLATE_NAME, sitePrefix, pageAlias);
prepareWebsiteViewData(usersWebsite, location);
}
// 2) check related webpages
// 2) Check related webpages
Webpage webpage = getWebsitesWebpage(usersWebsite, pageAlias);
if (webpage != null) {
if (webpage != null && usersWebsite != null) {
Topic htmlTemplate = webpage.getHTMLTemplate();
String templateFilename = getTemplateFileName(htmlTemplate);
prepareGenericViewData(templateFilename, sitePrefix, pageAlias);
prepareWebsiteViewData(usersWebsite, pageAlias);
log.info("Preparing WEBPAGE view data \""+webpage.getTitle().toString()+"\" for template=\"" + templateFilename
+ "\", website=\"" + sitePrefix +"\"");
dmx.fireEvent(WEBPAGE_REQUESTED, context(), pageAlias, sitePrefix);
log.info("Preparing WEBPAGE view data \""+webpage.getTitle().toString()+"\" ...");
preparePageViewData(webpage);
return getWebpageTemplate(webpage);
return getWebpageTemplate(webpage, templateFilename);
}
log.info("=> /" + pageAlias + " webpage for \"" +sitePrefix+ "\"s website not found.");
// 3) check if it is a users redirect
Expand Down Expand Up @@ -817,14 +820,14 @@ private Viewable getCustomRootResourcePage(String pageAlias) {
return null;
}

private Viewable getWebpageTemplate(Webpage page) {
private Viewable getWebpageTemplate(Webpage page, String templateName) {
try {
// while logged in users can (potentially) browse a drafted webpage
if (isNotAllowedToAccessDraft(page)) {
log.fine("401 => /" + page.getWebAlias() + " is a DRAFT (yet unpublished)");
return view("401");
} else {
return view(SIMPLE_PAGE_TEMPLATE_NAME);
return view(templateName);
}
} catch (RuntimeException re) {
throw new RuntimeException("Page Template for Webpage Topic (ID: "
Expand Down Expand Up @@ -1004,6 +1007,11 @@ public int compare(Section s1, Section s2) {
return all;
}

private String getTemplateFileName(Topic templateName) {
if (templateName == null) return SIMPLE_PAGE_TEMPLATE_NAME;
return templateName.getUri().substring("de.mikromedia.template_".length());
}

@Override
public void overrideFrontpageTemplate(String fileName) {
this.frontPageTemplateName = fileName;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/de/mikromedia/webpages/WebpageService.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public interface WebpageService {
public static final String CUSTOM_SCRIPT_PATH = "de.mikromedia.javascript_path";
public static final String WEBPAGE_ALIAS = "de.mikromedia.page.web_alias";
public static final String WEBPAGE_IS_DRAFT = "de.mikromedia.page.is_draft";
public static final String WEBPAGE_TEMPLATE = "de.mikromedia.page.template";

// ### TODO: Switch to related "Person" topics for authorship
public static final String AUTHOR_NAME = "de.mikromedia.page.author_name";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ public void run () {

Topic webpagesWorkspace = dmx.getPrivilegedAccess().getWorkspace(WebpagePlugin.WEBPAGES_WS_URI);
TopicType site = dmx.getTopicType("de.mikromedia.site");
DMXType assocDef = site.addCompDef(mf.newCompDefModel(site.getUri(), "de.mikromedia.site.footer_fragment_name", "dmx.core.one"));
workspacesService.assignTypeToWorkspace(dmx.getTopicType("de.mikromedia.site.footer_fragment_name"), webpagesWorkspace.getId());
workspacesService.assignTypeToWorkspace(assocDef, webpagesWorkspace.getId());
site.addCompDef(mf.newCompDefModel(site.getUri(), "de.mikromedia.site.footer_fragment_name", "dmx.core.one"));
workspacesService.assignTypeToWorkspace(site, webpagesWorkspace.getId());

}

Expand Down
27 changes: 0 additions & 27 deletions src/main/java/de/mikromedia/webpages/migrations/Migration21.java

This file was deleted.

39 changes: 39 additions & 0 deletions src/main/java/de/mikromedia/webpages/migrations/Migration22.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package de.mikromedia.webpages.migrations;


import de.mikromedia.webpages.WebpagePlugin;
import systems.dmx.accesscontrol.AccessControlService;
import static systems.dmx.core.Constants.ONE;
import systems.dmx.core.Topic;
import systems.dmx.core.TopicType;
import systems.dmx.core.service.Inject;
import systems.dmx.core.service.Migration;
import systems.dmx.workspaces.WorkspacesService;

public class Migration22 extends Migration {

@Inject WorkspacesService workspaces;
@Inject AccessControlService accessControlService;

@Override
public void run () {

// Assign new default pages
Topic webpagesWs = workspaces.getWorkspace(WebpagePlugin.WEBPAGES_WS_URI);
Topic bookmarksPage = dmx.getTopicByUri("de.mikromedia.bookmarks.page");
Topic contactsPage = dmx.getTopicByUri("de.mikromedia.contacts.page");
Topic notesPage = dmx.getTopicByUri("de.mikromedia.notes.page");
Topic promutCss = dmx.getTopicByUri("de.mikromedia.iass_promut_style");
workspaces.assignToWorkspace(bookmarksPage, webpagesWs.getId());
workspaces.assignToWorkspace(contactsPage, webpagesWs.getId());
workspaces.assignToWorkspace(notesPage, webpagesWs.getId());
workspaces.assignToWorkspace(promutCss, webpagesWs.getId());
// Add "Page Template" value to "Webpage"
TopicType webpage = dmx.getTopicType("de.mikromedia.page");
TopicType pageTemplate = dmx.getTopicType("de.mikromedia.page.template");
webpage.addCompDef(mf.newCompDefModel(webpage.getUri(), pageTemplate.getUri(), ONE));
workspaces.assignTypeToWorkspace(webpage, webpagesWs.getId());

}

}
58 changes: 58 additions & 0 deletions src/main/java/de/mikromedia/webpages/migrations/Migration23.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package de.mikromedia.webpages.migrations;


import systems.dmx.accesscontrol.AccessControlService;
import systems.dmx.core.CompDef;
import systems.dmx.core.Topic;
import systems.dmx.core.TopicType;
import systems.dmx.core.ViewConfig;
import systems.dmx.core.service.Inject;
import systems.dmx.core.service.Migration;
import systems.dmx.workspaces.WorkspacesService;

public class Migration23 extends Migration {

@Inject WorkspacesService workspaces;
@Inject AccessControlService accessControlService;

@Override
public void run () {

// Migrate default "page" template into all existing "Webpage" topics
// Activate "Select" Widgets for new Child Topic Types
TopicType websote = dmx.getTopicType("de.mikromedia.site");
CompDef footerFragment = websote.getCompDef("de.mikromedia.site.footer_fragment_name");
ViewConfig cdefAttachment = footerFragment.getViewConfig();
cdefAttachment.setConfigValueRef("dmx.webclient.view_config", "dmx.webclient.widget", "dmx.webclient.select");
TopicType webpage = dmx.getTopicType("de.mikromedia.page");
CompDef pageTemplate = webpage.getCompDef("de.mikromedia.page.template");
ViewConfig styleConfig = pageTemplate.getViewConfig();
styleConfig.setConfigValueRef("dmx.webclient.view_config", "dmx.webclient.widget", "dmx.webclient.select");
webpage.removeCompDef("de.mikromedia.page.author_name");
// Removing "Author Name" from "Webpage" topic
TopicType authorName = dmx.getTopicType("de.mikromedia.page.author_name");
authorName.delete();
// Remove Un-Maintained Section Layouts
Topic mapWidget = dmx.getTopicByUri("de.mikromedia.layout.map_widget");
mapWidget.delete();
Topic embed = dmx.getTopicByUri("de.mikromedia.layout.embed");
embed.delete();
// Authors/Contributors
// User Profile
// Rename Topics
// de.mikromedia.footer.footer-new
// de.mikromedia.footer.qpq-footer
// de.mikromedia.footer.dmx-footer
// de.mikromedia.footer.footer-links
// de.mikromedia.layout.native_embed
// de.mikromedia.layout.single_tile
// de.mikromedia.layout.quote_section
// de.mikromedia.layout.two_tiles
// de.mikromedia.layout.tiles_ten_six
// de.mikromedia.layout.n_tiles
// de.mikromedia.layout.2_and_n_tiles
// de.mikromedia.standard_site

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public void run () {
workspacesService.assignTypeToWorkspace(sitePrefix, webpagesWorkspace.getId());
// 2) Add website prefix to "Website" type
TopicType siteType = dmx.getTopicType("de.mikromedia.site");
// register site.prefix as identityAttr=True
siteType.addCompDef(mf.newCompDefModel(null, true, false, siteType.getUri(), sitePrefix.getUri(), "dmx.core.one"));
// Fixme: ### If webclient is capable of providing identityAttributes register site.prefix as identityAttr=True
siteType.addCompDef(mf.newCompDefModel(null, false, false, siteType.getUri(), sitePrefix.getUri(), "dmx.core.one"));
// 3) Fetch all website topcis and copy username (former prefix) into new site prefix child
List<Topic> websites = dmx.getTopicsByType("de.mikromedia.site");
for (Topic website : websites) {
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/de/mikromedia/webpages/model/Section.java
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,13 @@ public String getRelatedTopicFilePath() {
return null;
}

public String getRelatedTopicFileHTML() {
if (this.relatedTopic != null && this.relatedTopic.getTypeUri().equals("dmx.files.file")) {
return this.relatedTopic.getChildTopics().getString("dmx.files.file_content", null);
}
return null;
}

public String getRelatedTopicFileSize() {
if (this.relatedTopic != null && this.relatedTopic.getTypeUri().equals("dmx.files.file")) {
return humanReadableByteCount(this.relatedTopic.getChildTopics().getLong("dmx.files.size", 0), true);
Expand Down
12 changes: 8 additions & 4 deletions src/main/java/de/mikromedia/webpages/model/Webpage.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import static de.mikromedia.webpages.WebpageService.WEBPAGE_CONTENT;
import static de.mikromedia.webpages.WebpageService.WEBPAGE_CSS;
import static de.mikromedia.webpages.WebpageService.WEBPAGE_IS_DRAFT;
import static de.mikromedia.webpages.WebpageService.WEBPAGE_TEMPLATE;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
Expand Down Expand Up @@ -55,6 +56,10 @@ public String getDescription() {
return page.getChildTopics().getString(WEBPAGE_ABOUT, null);
}

public Topic getHTMLTemplate() {
return page.getChildTopics().getTopicOrNull(WEBPAGE_TEMPLATE);
}

public String getMainHTML() {
return page.getChildTopics().getString(WEBPAGE_CONTENT, null);
}
Expand Down Expand Up @@ -102,7 +107,7 @@ public boolean isDraft() {
return isDraft;
}

public String getAuthorNames() {
/** public String getAuthorNames() {
String nameOfAuthors = "";
List<RelatedTopic> authorNames = page.getChildTopics().getTopicsOrNull(AUTHOR_NAME);
if (authorNames != null) {
Expand All @@ -116,7 +121,7 @@ public String getAuthorNames() {
}
}
return nameOfAuthors;
}
} **/

public JSONObject toJSON() {
try {
Expand All @@ -126,7 +131,6 @@ public JSONObject toJSON() {
.put("main", getMainHTML())
.put("modified", getModificationDate())
.put("created", getCreationDate())
.put("author_names", getAuthorNames())
.put("web_alias", getWebAlias());
/**
* .put("web_description", webDescription) *
Expand All @@ -139,7 +143,7 @@ public JSONObject toJSON() {

private boolean isWebpageTopic() {
if (this.page == null) return false;
return (this.page.getTypeUri().equals("de.mikromedia.page"));
return (this.page.getTypeUri().equals(WEBPAGE));
}

}
27 changes: 23 additions & 4 deletions src/main/resources/migrations/migration1.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
page
[
{
"topic_types": [
Expand Down Expand Up @@ -331,15 +330,26 @@ page
"compDefs": [
{
"childTypeUri": "de.mikromedia.site.name",
"childCardinalityUri": "dmx.core.one"
"childCardinalityUri": "dmx.core.one",
"isIdentityAttribute": true
},
{
"childTypeUri": "de.mikromedia.site.caption",
"childCardinalityUri": "dmx.core.one"
},
{
"childTypeUri": "de.mikromedia.site.stylesheet",
"childCardinalityUri": "dmx.core.one"
"childCardinalityUri": "dmx.core.one",
"viewConfigTopics": [
{
"typeUri": "dmx.webclient.view_config",
"children": {
"dmx.webclient.widget": "ref_uri:dmx.webclient.select",
"dmx.webclient.clearable": true,
"dmx.webclient.customizable": true
}
}
]
},
{
"childTypeUri": "de.mikromedia.site.about_html",
Expand Down Expand Up @@ -409,7 +419,16 @@ page
{
"childTypeUri": "de.mikromedia.redirect.status_code",
"childCardinalityUri": "dmx.core.one",
"isIdentityAttribute": true
"isIdentityAttribute": true,
"viewConfigTopics": [
{
"typeUri": "dmx.webclient.view_config",
"children": {
"dmx.webclient.widget": "ref_uri:dmx.webclient.select",
"dmx.webclient.clearable": true
}
}
]
}
],
"viewConfigTopics": [
Expand Down
Loading

0 comments on commit 8b2ce96

Please sign in to comment.