CCM NG: Several small changes

git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@3832 8810af33-2d31-482b-a856-94f89814c4df
pull/2/head
jensp 2016-01-31 10:13:46 +00:00
parent 3be60416f8
commit 34907dfe89
18 changed files with 193 additions and 80 deletions

View File

@ -29,6 +29,8 @@ import java.util.List;
import java.util.Objects;
import java.util.StringJoiner;
import javax.enterprise.inject.spi.CDI;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
@ -50,12 +52,14 @@ public final class UIConfig {
private String userRedirectUrl = "/permissions/";
@Setting
private String workspaceUrl = "pvt/";
private String workspaceUrl = "/pvt/";
public static UIConfig getConfig() {
final CdiUtil cdiUtil = new CdiUtil();
final ConfigurationManager confManager = cdiUtil.findBean(
ConfigurationManager.class);
// final CdiUtil cdiUtil = new CdiUtil();
// final ConfigurationManager confManager = cdiUtil.findBean(
// ConfigurationManager.class);
final ConfigurationManager confManager = CDI.current().select(
ConfigurationManager.class).get();
return confManager.findConfiguration(UIConfig.class);
}

View File

@ -18,6 +18,7 @@
*/
package com.arsdigita.ui.admin;
import org.libreccm.modules.InstallEvent;
import org.libreccm.web.CcmApplication;
import org.libreccm.web.AbstractCcmApplicationSetup;
@ -31,8 +32,8 @@ public class AdminApplicationSetup extends AbstractCcmApplicationSetup {
public static final String ADMIN_APP_NAME = "CcmAdmin";
public AdminApplicationSetup(final EntityManager entityManager) {
super(entityManager);
public AdminApplicationSetup(final InstallEvent event) {
super(event);
}
@Override

View File

@ -547,10 +547,8 @@ class GroupAdministrationTab extends LayoutPanel implements AdminConstants,
//
// });
// body.add(deleteLink);
// return main.addSegment(GROUP_EXTREME_ACTIONS_HEADER,
// body);
throw new UnsupportedOperationException();
return main.addSegment(GROUP_EXTREME_ACTIONS_HEADER,
body);
}
/**

View File

@ -18,10 +18,10 @@
*/
package com.arsdigita.ui.login;
import org.libreccm.modules.InstallEvent;
import org.libreccm.web.AbstractCcmApplicationSetup;
import org.libreccm.web.CcmApplication;
import javax.persistence.EntityManager;
/**
*
@ -31,8 +31,8 @@ public class LoginApplicationSetup extends AbstractCcmApplicationSetup {
public static final String LOGIN_APP_NAME = "Login";
public LoginApplicationSetup(final EntityManager entityManager) {
super(entityManager);
public LoginApplicationSetup(final InstallEvent event) {
super(event);
}
@Override

View File

@ -41,6 +41,16 @@ import javax.servlet.http.HttpServletResponse;
import org.apache.shiro.subject.Subject;
import org.libreccm.web.ApplicationManager;
import org.libreccm.web.ApplicationType;
import java.util.Iterator;
import java.util.Set;
import javax.enterprise.context.spi.CreationalContext;
import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.BeanManager;
import javax.enterprise.inject.spi.CDI;
import javax.servlet.http.HttpServlet;
/**
* <p>
@ -138,10 +148,10 @@ public class CCMDispatcherServlet extends BaseServlet {
if (subject.isAuthenticated()) {
// User is logged in, redirect to user redirect page
throw new RedirectSignal(URL.there(request,
UI
.getUserRedirectURL(request)),
false);
throw new RedirectSignal(
URL.there(request,
UI.getUserRedirectURL(request)),
false);
} else {
// User is *not* logged in, display public front page
throw new RedirectSignal(URL.there(request,
@ -206,7 +216,9 @@ public class CCMDispatcherServlet extends BaseServlet {
BaseApplicationServlet.APPLICATION_ID_ATTRIBUTE,
spec.getAppID());
request.setAttribute(DISPATCHED_ATTRIBUTE, Boolean.TRUE);
forward(spec.getTypeContextPath(), spec.target(path), request,
forward(spec.getTypeContextPath(),
spec.target(path),
request,
response);
// return true;
}
@ -266,7 +278,7 @@ public class CCMDispatcherServlet extends BaseServlet {
LOGGER.debug("forwarding from context \"{}\" to context \"{}\"...",
getServletContext(), context);
forward(context.getRequestDispatcher(target),
forward(getServletContext().getRequestDispatcher(target),
request,
response);
}
@ -304,8 +316,6 @@ public class CCMDispatcherServlet extends BaseServlet {
path);
}
// final CcmApplication application = appRepository
// .retrieveApplicationForPath(path);
final CcmApplication application = appManager
.findApplicationByPath(path);
@ -313,7 +323,7 @@ public class CCMDispatcherServlet extends BaseServlet {
LOGGER.warn("No application found for path \"{}\".", path);
return null;
} else {
return new ApplicationSpec(application);
return new ApplicationSpec(application, appManager);
}
}
@ -338,12 +348,16 @@ public class CCMDispatcherServlet extends BaseServlet {
private final String m_instanceURI;
private final String m_typeURI;
private final String m_typeContextPath;
private final ApplicationManager appManager;
/**
*
* @param app
*/
ApplicationSpec(CcmApplication app) {
ApplicationSpec(final CcmApplication app,
final ApplicationManager appManager) {
this.appManager = appManager;
if (app == null) {
throw new NullPointerException("app");
}
@ -356,9 +370,56 @@ public class CCMDispatcherServlet extends BaseServlet {
.getAnnotation(ServletPath.class)
.value();
} else {
m_typeURI = URL.SERVLET_DIR + "/legacy-adapter";
// final ApplicationManager appManager = CDI.current().select(
// ApplicationManager.class).get();
// final BeanManager beanManager = CDI.current().getBeanManager();
// final Set<Bean<?>> beans = beanManager.getBeans(
// ApplicationManager.class);
// final Iterator<Bean<?>> iterator = beans.iterator();
// final ApplicationManager appManager;
// if (iterator.hasNext()) {
// @SuppressWarnings("unchecked")
// final Bean<ApplicationManager> bean
// = (Bean<ApplicationManager>) iterator
// .next();
// final CreationalContext<ApplicationManager> ctx
// = beanManager
// .createCreationalContext(bean);
//
// appManager = (ApplicationManager) beanManager.getReference(
// bean, ApplicationManager.class, ctx);
// } else {
// LOGGER.error("Failed to find {}.",
// ApplicationManager.class.getName());
// throw new IllegalArgumentException(String.format(
// "Failed to find %s",
// ApplicationManager.class.getName()));
// }
final ApplicationType appType = appManager.getApplicationTypes()
.get(app.getApplicationType());
final Class<? extends HttpServlet> appServletClass = appType
.servlet();
final WebServlet servletAnnotation = appServletClass
.getAnnotation(WebServlet.class);
if (servletAnnotation != null
&& servletAnnotation.urlPatterns() != null
&& servletAnnotation.urlPatterns().length > 0) {
if (servletAnnotation.urlPatterns()[0].endsWith("*")) {
m_typeURI = servletAnnotation
.urlPatterns()[0]
.substring(0,
servletAnnotation
.urlPatterns()[0]
.length() - 1);
} else {
m_typeURI = servletAnnotation.urlPatterns()[0];
}
} else {
m_typeURI = "";
}
}
m_typeContextPath = "";
if (Assert.isEnabled()) {

View File

@ -84,14 +84,11 @@ public class CategoryRepository extends AbstractEntityRepository<Long, Category>
+ "Valid path format: domainKey:path");
}
final Domain domain;
try {
domain = domainRepo.findByDomainKey(tokens[0]);
} catch (NoResultException ex) {
final Domain domain = domainRepo.findByDomainKey(tokens[0]);
if (domain == null) {
throw new InvalidCategoryPathException(String.format(
"No domain identified by the key '%s' found.",
tokens[0]),
ex);
tokens[0]));
}
return findByPath(domain, tokens[1]);

View File

@ -24,13 +24,11 @@ import static org.libreccm.core.CoreConstants.*;
import org.hibernate.validator.constraints.NotBlank;
import org.hibernate.validator.constraints.URL;
import org.libreccm.core.CcmObject;
import org.libreccm.jpa.utils.UriConverter;
import org.libreccm.l10n.LocalizedString;
import org.libreccm.web.CcmApplication;
import org.omg.CORBA.DomainManager;
import java.io.Serializable;
import java.net.URI;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
@ -39,14 +37,17 @@ import java.util.Objects;
import javax.persistence.AssociationOverride;
import javax.persistence.Column;
import javax.persistence.Convert;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToOne;
import javax.persistence.NamedAttributeNode;
import javax.persistence.NamedEntityGraph;
import javax.persistence.NamedEntityGraphs;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.NamedSubgraph;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
@ -62,7 +63,7 @@ import javax.xml.bind.annotation.XmlRootElement;
* as well as the {@code CategoryPurpose} entity from the old
* {@code ccm-core module}.
*
* A {@code Domain} can be mapped to multiple {@link CcmApplication}s. Normally
* A {@code Domain} can be mapped to multiple {@link CcmApplication}s. Normally
* This is used to make a {@code Domain} available in the application. The
* {@link CcmApplication}s to which a {@code Domain} is mapped are called
* <em>owners</em> of the domain.
@ -72,11 +73,24 @@ import javax.xml.bind.annotation.XmlRootElement;
@Entity
@Table(name = "CATEGORY_DOMAINS", schema = DB_SCHEMA)
@NamedQueries({
@NamedQuery(name="Domain.findByKey",
@NamedQuery(name = "Domain.findByKey",
query = "SELECT d FROM Domain d WHERE d.domainKey = :key"),
@NamedQuery(name="Domain.findByUri",
@NamedQuery(name = "Domain.findByUri",
query = "SELECT d FROM Domain d WHERE d.uri = :uri")
})
@NamedEntityGraphs({
@NamedEntityGraph(
name = "Domain.allCategories",
attributeNodes = {
@NamedAttributeNode(value = "root",
subgraph = "subCategories")},
subgraphs = {
@NamedSubgraph(
name = "subCategories",
attributeNodes = {
@NamedAttributeNode("subCategories")
})})
})
@XmlRootElement(name = "domain", namespace = CAT_XML_NS)
public class Domain extends CcmObject implements Serializable {
@ -106,10 +120,9 @@ public class Domain extends CcmObject implements Serializable {
* </pre>
*/
@Column(name = "URI", nullable = true, unique = true, length = 1024)
@Convert(converter = UriConverter.class)
@URL
@XmlElement(name = "uri", namespace = CAT_XML_NS)
private URI uri;
private String uri;
/**
* A human readable title for the {@code Domain}. The title can be
@ -184,11 +197,11 @@ public class Domain extends CcmObject implements Serializable {
this.domainKey = domainKey;
}
public URI getUri() {
public String getUri() {
return uri;
}
public void setUri(final URI uri) {
public void setUri(final String uri) {
this.uri = uri;
}

View File

@ -36,22 +36,53 @@ public class DomainManager {
@Inject
private ApplicationRepository applicationRepo;
@Inject
private DomainRepository domainRepo;
@Inject
private CategoryRepository categoryRepo;
@Inject
private EntityManager entityManager;
/**
* Creates a new domain with the provided key (name) and a root category
* with the provided name. The domain and the root category can be further
* customised after the creation.
*
* @param domainKey The key (name) of the new domain.
* @param rootCategoryName The name of the root category of the new domain.
* @return The new domain.
*/
public Domain createDomain(final String domainKey,
final String rootCategoryName) {
final Domain domain = new Domain();
domain.setDomainKey(domainKey);
domain.setVersion("1.0");
domain.setDisplayName(domainKey);
final Category root = new Category();
root.setName(rootCategoryName);
root.setDisplayName(rootCategoryName);
domain.setRoot(root);
categoryRepo.save(root);
domainRepo.save(domain);
return domain;
}
/**
* Adds a {@code CcmApplication} to the owners of a {@link Domain}. If the
* provided {@code CcmApplication} is already an owner of the provided
* {@code Domain} the method does nothing.
*
* @param application The {@code CcmApplication} to add to the owners of the
* {@code Domain}.
* @param domain The {@code Domain} to which owners the
* {@code CcmApplication is added}.
* {@code Domain}.
* @param domain The {@code Domain} to which owners the
* {@code CcmApplication is added}.
*/
public void addDomainOwner(final CcmApplication application,
final Domain domain) {
@ -60,24 +91,24 @@ public class DomainManager {
ownership.setOwner(application);
ownership.setOwnerOrder(domain.getOwners().size() + 1);
ownership.setDomainOrder(application.getDomains().size() + 1);
application.addDomain(ownership);
domain.addOwner(ownership);
entityManager.persist(ownership);
applicationRepo.save(application);
domainRepo.save(domain);
}
/**
* Removes a {@code CcmApplication} from the owners of a {@code Domain}. If the
* provided {@code CcmApplication} is not an owner of the provided
* Removes a {@code CcmApplication} from the owners of a {@code Domain}. If
* the provided {@code CcmApplication} is not an owner of the provided
* {@code Domain} the method does nothing.
*
* @param application The {@code CcmApplication} to remove from the owners of
* the provided {@code Domain}.
* @param domain The {@code Domain} from which owners the provided
* {@code CcmApplication} should be removed.
* @param application The {@code CcmApplication} to remove from the owners
* of the provided {@code Domain}.
* @param domain The {@code Domain} from which owners the provided
* {@code CcmApplication} should be removed.
*/
public void removeDomainOwner(final CcmApplication application,
final Domain domain) {
@ -87,10 +118,10 @@ public class DomainManager {
/**
* Determines if a {@link CcmApplication} is an owner of {@link Domain}.
*
*
* @param application The {@code CcmApplication} to test.
* @param domain The {@code Domain} to test.
* @return {@code true} if the provided {@code CcmApplication} is an owner
* @return {@code true} if the provided {@code CcmApplication} is an owner
* of the provided {@code Domain}, {@code false} otherwise.
*/
public boolean isDomainOwner(final CcmApplication application,

View File

@ -24,6 +24,7 @@ import java.net.URI;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.persistence.EntityGraph;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.TypedQuery;
@ -61,6 +62,10 @@ public class DomainRepository extends AbstractEntityRepository<Long, Domain> {
final TypedQuery<Domain> query = entityManager.createNamedQuery(
"Domain.findByKey", Domain.class);
query.setParameter("key", domainKey);
final EntityGraph<?> graph = entityManager.getEntityGraph(
"Domain.allCategories");
query.setHint("javax.persistence.fetchgraph", graph);
try {
return query.getSingleResult();

View File

@ -52,7 +52,7 @@ public class ConfigurationManager {
@Inject
private SettingConverter settingConverter;
@Inject
private CategoryManager categoryManager;
@ -269,7 +269,6 @@ public class ConfigurationManager {
// "No setting type for value type \"%s\".", valueTypeName));
// }
// }
/**
* Sets a value on a setting in the registry.
*
@ -348,8 +347,7 @@ public class ConfigurationManager {
return null;
}
final Domain registry = domainRepo
.findByDomainKey(REGISTRY_DOMAIN);
final Domain registry = domainRepo.findByDomainKey(REGISTRY_DOMAIN);
if (categoryRepo.findByPath(registry, confName) == null) {
return conf;
}
@ -453,7 +451,7 @@ public class ConfigurationManager {
categoryPath);
return categories[categories.length - 1];
}
private String buildCategoryPath(final String[] tokens,
final int index) {
final StringJoiner joiner = new StringJoiner(".");

View File

@ -25,6 +25,7 @@ import com.arsdigita.ui.login.LoginApplicationCreator;
import com.arsdigita.ui.login.LoginServlet;
import com.arsdigita.ui.login.LoginApplicationSetup;
import org.libreccm.categorization.RegistrySetup;
import org.libreccm.modules.CcmModule;
import org.libreccm.modules.InitEvent;
import org.libreccm.modules.InstallEvent;
@ -33,7 +34,6 @@ import org.libreccm.modules.ShutdownEvent;
import org.libreccm.modules.UnInstallEvent;
import org.libreccm.security.SystemUsersSetup;
import javax.persistence.EntityManager;
import org.libreccm.web.ApplicationType;
@ -98,16 +98,19 @@ public class CcmCore implements CcmModule {
@Override
public void install(final InstallEvent event) {
final EntityManager entityManager = event.getEntityManager();
// final EntityManager entityManager = event.getEntityManager();
final SystemUsersSetup systemUsersSetup = new SystemUsersSetup(
entityManager);
event);
systemUsersSetup.setupSystemUsers();
final AdminApplicationSetup adminSetup = new AdminApplicationSetup(entityManager);
final RegistrySetup registrySetup = new RegistrySetup(event);
registrySetup.setup();
final AdminApplicationSetup adminSetup = new AdminApplicationSetup(event);
adminSetup.setup();
final LoginApplicationSetup loginSetup = new LoginApplicationSetup(entityManager);
final LoginApplicationSetup loginSetup = new LoginApplicationSetup(event);
loginSetup.setup();
}

View File

@ -22,6 +22,7 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.libreccm.core.CcmCore;
import org.libreccm.core.EmailAddress;
import org.libreccm.modules.InstallEvent;
import java.io.IOException;
import java.io.InputStream;
@ -45,8 +46,8 @@ public class SystemUsersSetup {
private final EntityManager entityManager;
public SystemUsersSetup(final EntityManager entityManager) {
this.entityManager = entityManager;
public SystemUsersSetup(final InstallEvent event) {
this.entityManager = event.getEntityManager();
}
public void setupSystemUsers() {

View File

@ -18,6 +18,8 @@
*/
package org.libreccm.web;
import org.libreccm.modules.InstallEvent;
import javax.persistence.EntityManager;
/**
@ -28,8 +30,8 @@ public abstract class AbstractCcmApplicationSetup {
private final EntityManager entityManager;
public AbstractCcmApplicationSetup(final EntityManager entityManager) {
this.entityManager = entityManager;
public AbstractCcmApplicationSetup(final InstallEvent event) {
this.entityManager = event.getEntityManager();
}
protected EntityManager getEntityManager() {

View File

@ -55,9 +55,6 @@ import java.math.BigDecimal;
import javax.inject.Inject;
import org.jboss.arquillian.persistence.ShouldMatchDataSet;
import org.libreccm.categorization.Category;
import javax.persistence.TypedQuery;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;

View File

@ -47,11 +47,12 @@ public class DatasetsTest extends DatasetsVerifier {
return Arrays.asList(new String[]{
"/datasets/org/libreccm/configuration/ConfigurationManagerTest/after-save-changed.yml",
"/datasets/org/libreccm/configuration/ConfigurationManagerTest/after-save-new.yml",
"/datasets/org/libreccm/configuration/ConfigurationManagerTest/data.yml"});
"/datasets/org/libreccm/configuration/ConfigurationManagerTest/data.yml",
});
}
public DatasetsTest(final String datasetPath) {
super(datasetPath);;
super(datasetPath);
}
@Override

View File

@ -44,12 +44,6 @@
<version>${project.parent.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.libreccm</groupId>
<artifactId>ccm-testutils</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>

View File

@ -23,6 +23,7 @@ package org.libreccm.testutils;
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public enum DatasetType {
FLAT_XML,
JSON,
YAML
}

View File

@ -42,6 +42,7 @@ import org.junit.runners.Parameterized;
import static org.libreccm.testutils.DatasetType.*;
import org.dbunit.dataset.xml.FlatXmlDataSetBuilder;
import org.jboss.arquillian.persistence.dbunit.dataset.yaml.YamlDataSet;
import java.nio.charset.StandardCharsets;
@ -124,6 +125,11 @@ public class DatasetsVerifier {
//Get dataset to test
final IDataSet dataSet;
switch(getDatasetType()) {
case FLAT_XML:
final FlatXmlDataSetBuilder builder = new FlatXmlDataSetBuilder();
dataSet = builder.build(getClass().getResourceAsStream(
datasetPath));
break;
case JSON:
dataSet = new JsonDataSet(getClass()
.getResourceAsStream(datasetPath));