CCM NG: Creating new domains using /ccm/admin/
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4025 8810af33-2d31-482b-a856-94f89814c4dfpull/2/head
parent
b14529823b
commit
189c432378
|
|
@ -19,14 +19,19 @@
|
||||||
package com.arsdigita.ui.admin.categories;
|
package com.arsdigita.ui.admin.categories;
|
||||||
|
|
||||||
import com.arsdigita.bebop.Form;
|
import com.arsdigita.bebop.Form;
|
||||||
|
import com.arsdigita.bebop.FormData;
|
||||||
import com.arsdigita.bebop.Label;
|
import com.arsdigita.bebop.Label;
|
||||||
|
import com.arsdigita.bebop.Page;
|
||||||
import com.arsdigita.bebop.PageState;
|
import com.arsdigita.bebop.PageState;
|
||||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
||||||
import com.arsdigita.bebop.SaveCancelSection;
|
import com.arsdigita.bebop.SaveCancelSection;
|
||||||
import com.arsdigita.bebop.form.Date;
|
import com.arsdigita.bebop.form.Date;
|
||||||
import com.arsdigita.bebop.form.TextField;
|
import com.arsdigita.bebop.form.TextField;
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
import com.arsdigita.globalization.GlobalizedMessage;
|
||||||
|
|
||||||
|
import org.apache.logging.log4j.util.Strings;
|
||||||
import org.libreccm.categorization.Domain;
|
import org.libreccm.categorization.Domain;
|
||||||
|
import org.libreccm.categorization.DomainManager;
|
||||||
import org.libreccm.categorization.DomainRepository;
|
import org.libreccm.categorization.DomainRepository;
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
import org.libreccm.cdi.utils.CdiUtil;
|
||||||
|
|
||||||
|
|
@ -42,6 +47,7 @@ public class DomainForm extends Form {
|
||||||
private static final String VERSION = "version";
|
private static final String VERSION = "version";
|
||||||
private static final String DOMAIN_URI = "domainUri";
|
private static final String DOMAIN_URI = "domainUri";
|
||||||
private static final String DOMAIN_KEY = "domainKey";
|
private static final String DOMAIN_KEY = "domainKey";
|
||||||
|
private static final String ROOT_CATEGORY_NAME = "rootCategoryName";
|
||||||
|
|
||||||
private final ParameterSingleSelectionModel<String> selectedDomainId;
|
private final ParameterSingleSelectionModel<String> selectedDomainId;
|
||||||
|
|
||||||
|
|
@ -49,6 +55,7 @@ public class DomainForm extends Form {
|
||||||
private final TextField domainUri;
|
private final TextField domainUri;
|
||||||
private final TextField version;
|
private final TextField version;
|
||||||
private final Date released;
|
private final Date released;
|
||||||
|
private final TextField rootCategoryName;
|
||||||
private final SaveCancelSection saveCancelSection;
|
private final SaveCancelSection saveCancelSection;
|
||||||
|
|
||||||
public DomainForm(
|
public DomainForm(
|
||||||
|
|
@ -103,18 +110,117 @@ public class DomainForm extends Form {
|
||||||
ADMIN_BUNDLE));
|
ADMIN_BUNDLE));
|
||||||
add(released);
|
add(released);
|
||||||
|
|
||||||
|
rootCategoryName = new TextField(ROOT_CATEGORY_NAME);
|
||||||
|
rootCategoryName.setLabel(new GlobalizedMessage(
|
||||||
|
"ui.admin.categories.domain_form.fields.root_category_name",
|
||||||
|
ADMIN_BUNDLE));
|
||||||
|
add(rootCategoryName);
|
||||||
|
|
||||||
saveCancelSection = new SaveCancelSection();
|
saveCancelSection = new SaveCancelSection();
|
||||||
add(saveCancelSection);
|
add(saveCancelSection);
|
||||||
|
|
||||||
|
addInitListener(e -> {
|
||||||
|
final PageState state = e.getPageState();
|
||||||
|
|
||||||
|
if (selectedDomainId.getSelectedKey(state) == null) {
|
||||||
|
rootCategoryName.setVisible(state, true);
|
||||||
|
} else {
|
||||||
|
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
|
final DomainRepository domainRepository = cdiUtil.findBean(
|
||||||
|
DomainRepository.class);
|
||||||
|
final Domain domain = domainRepository.findById(Long.parseLong(
|
||||||
|
selectedDomainId.getSelectedKey(state)));
|
||||||
|
|
||||||
|
domainKey.setValue(state, domain.getDomainKey());
|
||||||
|
domainUri.setValue(state, domain.getUri());
|
||||||
|
version.setValue(state, domain.getVersion());
|
||||||
|
released.setValue(state, domain.getReleased());
|
||||||
|
|
||||||
|
rootCategoryName.setVisible(state, false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
addValidationListener(e -> {
|
addValidationListener(e -> {
|
||||||
|
final PageState state = e.getPageState();
|
||||||
|
|
||||||
|
if (saveCancelSection.getSaveButton().isSelected(state)) {
|
||||||
|
final FormData data = e.getFormData();
|
||||||
|
final String domainKeyData = data.getString(DOMAIN_KEY);
|
||||||
|
final String versionData = data.getString(VERSION);
|
||||||
|
|
||||||
|
if (Strings.isBlank(domainKeyData)) {
|
||||||
|
data.addError(
|
||||||
|
DOMAIN_KEY,
|
||||||
|
new GlobalizedMessage(
|
||||||
|
"ui.admin.categories.domain_form.errors.domain_key_blank",
|
||||||
|
ADMIN_BUNDLE));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Strings.isBlank(versionData)) {
|
||||||
|
data.addError(
|
||||||
|
DOMAIN_KEY,
|
||||||
|
new GlobalizedMessage(
|
||||||
|
"ui.admin.categories.domain_form.errors.version_blank",
|
||||||
|
ADMIN_BUNDLE));
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
addProcessListener(e -> {
|
addProcessListener(e -> {
|
||||||
final PageState state = e.getPageState();
|
final PageState state = e.getPageState();
|
||||||
|
|
||||||
|
if (saveCancelSection.getSaveButton().isSelected(state)) {
|
||||||
|
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
|
final DomainRepository domainRepository = cdiUtil.findBean(
|
||||||
|
DomainRepository.class);
|
||||||
|
final DomainManager domainManager = cdiUtil.findBean(
|
||||||
|
DomainManager.class);
|
||||||
|
|
||||||
|
final FormData data = e.getFormData();
|
||||||
|
final String domainKeyData = data.getString(DOMAIN_KEY);
|
||||||
|
final String domainUriData;
|
||||||
|
if (Strings.isBlank(data.getString(DOMAIN_URI))) {
|
||||||
|
domainUriData = null;
|
||||||
|
} else {
|
||||||
|
domainUriData = data.getString(DOMAIN_URI);
|
||||||
|
}
|
||||||
|
final String versionData = data.getString(VERSION);
|
||||||
|
final java.util.Date releasedData = (java.util.Date) data.get(
|
||||||
|
RELEASED);
|
||||||
|
final String rootCategoryNameData = data.getString(
|
||||||
|
ROOT_CATEGORY_NAME);
|
||||||
|
|
||||||
|
final Domain domain;
|
||||||
|
if (selectedDomainId.getSelectedKey(state) == null) {
|
||||||
|
if (Strings.isBlank(rootCategoryNameData)) {
|
||||||
|
domain = domainManager.createDomain(domainKeyData,
|
||||||
|
domainKeyData);
|
||||||
|
} else {
|
||||||
|
domain = domainManager.createDomain(
|
||||||
|
domainKeyData, rootCategoryNameData);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
domain = domainRepository.findById(Long.parseLong(
|
||||||
|
selectedDomainId.getSelectedKey(state)));
|
||||||
|
}
|
||||||
|
domain.setDomainKey(domainKeyData);
|
||||||
|
domain.setUri(domainUriData);
|
||||||
|
domain.setVersion(versionData);
|
||||||
|
domain.setReleased(releasedData);
|
||||||
|
|
||||||
|
domainRepository.save(domain);
|
||||||
|
}
|
||||||
|
|
||||||
categoriesTab.hideNewDomainForm(state);
|
categoriesTab.hideNewDomainForm(state);
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void register(final Page page) {
|
||||||
|
super.register(page);
|
||||||
|
|
||||||
|
page.setVisibleDefault(rootCategoryName, false);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -182,7 +182,7 @@ public class DomainsTable extends Table {
|
||||||
final DomainRepository domainRepository = cdiUtil.findBean(
|
final DomainRepository domainRepository = cdiUtil.findBean(
|
||||||
DomainRepository.class);
|
DomainRepository.class);
|
||||||
if (Strings.isBlank(filterTerm)) {
|
if (Strings.isBlank(filterTerm)) {
|
||||||
domains = domainRepository.findAll();
|
domains = domainRepository.findAll("Domain.withOwners");
|
||||||
LOGGER.debug("Found {} domains in the database.",
|
LOGGER.debug("Found {} domains in the database.",
|
||||||
domains.size());
|
domains.size());
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -77,12 +77,15 @@ import javax.xml.bind.annotation.XmlRootElement;
|
||||||
query = "SELECT d FROM Domain d WHERE d.domainKey = :key"),
|
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"),
|
query = "SELECT d FROM Domain d WHERE d.uri = :uri"),
|
||||||
|
@NamedQuery(name = "Domain.findAll",
|
||||||
|
query = "SELECT d FROM Domain d ORDER BY d.domainKey"),
|
||||||
@NamedQuery(
|
@NamedQuery(
|
||||||
name = "Domain.search",
|
name = "Domain.search",
|
||||||
query
|
query
|
||||||
= "SELECT d FROM Domain d "
|
= "SELECT d FROM Domain d "
|
||||||
+ "WHERE d.domainKey LIKE CONCAT (LOWER(:term), '%') "
|
+ "WHERE d.domainKey LIKE CONCAT (LOWER(:term), '%') "
|
||||||
+ "OR d.uri LIKE CONCAT (LOWER(:term), '%')")
|
+ "OR d.uri LIKE CONCAT (LOWER(:term), '%') "
|
||||||
|
+ "ORDER BY d.domainKey")
|
||||||
})
|
})
|
||||||
@NamedEntityGraphs({
|
@NamedEntityGraphs({
|
||||||
@NamedEntityGraph(
|
@NamedEntityGraph(
|
||||||
|
|
@ -95,7 +98,13 @@ import javax.xml.bind.annotation.XmlRootElement;
|
||||||
name = "subCategories",
|
name = "subCategories",
|
||||||
attributeNodes = {
|
attributeNodes = {
|
||||||
@NamedAttributeNode("subCategories")
|
@NamedAttributeNode("subCategories")
|
||||||
})})
|
})}),
|
||||||
|
@NamedEntityGraph(
|
||||||
|
name = "Domain.withOwners",
|
||||||
|
attributeNodes = {
|
||||||
|
@NamedAttributeNode(value = "owners")
|
||||||
|
}
|
||||||
|
)
|
||||||
})
|
})
|
||||||
@DefaultEntityGraph("Domain.allCategories")
|
@DefaultEntityGraph("Domain.allCategories")
|
||||||
@XmlRootElement(name = "domain", namespace = CAT_XML_NS)
|
@XmlRootElement(name = "domain", namespace = CAT_XML_NS)
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,7 @@ public class DomainManager {
|
||||||
*
|
*
|
||||||
* @param domainKey The key (name) of the new domain.
|
* @param domainKey The key (name) of the new domain.
|
||||||
* @param rootCategoryName The name of the root category of the new domain.
|
* @param rootCategoryName The name of the root category of the new domain.
|
||||||
|
*
|
||||||
* @return The new domain.
|
* @return The new domain.
|
||||||
*/
|
*/
|
||||||
public Domain createDomain(final String domainKey,
|
public Domain createDomain(final String domainKey,
|
||||||
|
|
@ -123,6 +124,7 @@ public class DomainManager {
|
||||||
*
|
*
|
||||||
* @param application The {@code CcmApplication} to test.
|
* @param application The {@code CcmApplication} to test.
|
||||||
* @param domain The {@code Domain} 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.
|
* of the provided {@code Domain}, {@code false} otherwise.
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -19,9 +19,11 @@
|
||||||
package org.libreccm.categorization;
|
package org.libreccm.categorization;
|
||||||
|
|
||||||
import org.libreccm.core.AbstractEntityRepository;
|
import org.libreccm.core.AbstractEntityRepository;
|
||||||
|
import org.libreccm.core.DefaultEntityGraph;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import javax.enterprise.context.RequestScoped;
|
import javax.enterprise.context.RequestScoped;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
@ -51,6 +53,39 @@ public class DomainRepository extends AbstractEntityRepository<Long, Domain> {
|
||||||
return entity.getObjectId() == 0;
|
return entity.getObjectId() == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initNewEntity(final Domain domain) {
|
||||||
|
domain.setUuid(UUID.randomUUID().toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Domain> findAll() {
|
||||||
|
if (getEntityClass().isAnnotationPresent(DefaultEntityGraph.class)) {
|
||||||
|
return findAll(getEntityClass().getAnnotation(
|
||||||
|
DefaultEntityGraph.class).value());
|
||||||
|
} else {
|
||||||
|
final TypedQuery<Domain> query = getEntityManager()
|
||||||
|
.createNamedQuery("Domain.findAll", Domain.class);
|
||||||
|
return query.getResultList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Domain> findAll(final String entityGraphName) {
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
final EntityGraph<Domain> entityGraph = (EntityGraph<Domain>) entityManager.
|
||||||
|
getEntityGraph(entityGraphName);
|
||||||
|
return findAll(entityGraph);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Domain> findAll(final EntityGraph<Domain> entityGraph) {
|
||||||
|
final TypedQuery<Domain> query = getEntityManager()
|
||||||
|
.createNamedQuery("Domain.findAll", Domain.class);
|
||||||
|
query.setHint(FETCH_GRAPH_HINT_KEY, entityGraph);
|
||||||
|
return query.getResultList();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find the {@link Domain} identified by the provided {@code domainKey}.
|
* Find the {@link Domain} identified by the provided {@code domainKey}.
|
||||||
*
|
*
|
||||||
|
|
@ -95,6 +130,9 @@ public class DomainRepository extends AbstractEntityRepository<Long, Domain> {
|
||||||
final TypedQuery<Domain> query = entityManager.createNamedQuery(
|
final TypedQuery<Domain> query = entityManager.createNamedQuery(
|
||||||
"Domain.search", Domain.class);
|
"Domain.search", Domain.class);
|
||||||
query.setParameter("term", term);
|
query.setParameter("term", term);
|
||||||
|
final EntityGraph<?> graph = entityManager.getEntityGraph(
|
||||||
|
"Domain.withOwners");
|
||||||
|
query.setHint("javax.persistence.fetchgraph", graph);
|
||||||
|
|
||||||
return query.getResultList();
|
return query.getResultList();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -358,3 +358,6 @@ ui.admin.categories.domain_form.fields.domain_key=Key
|
||||||
ui.admin.categories.domain_form.fields.domain_uri=URI
|
ui.admin.categories.domain_form.fields.domain_uri=URI
|
||||||
ui.admin.categories.domain_form.fields.version=Version
|
ui.admin.categories.domain_form.fields.version=Version
|
||||||
ui.admin.categories.domain_form.fields.released=Released
|
ui.admin.categories.domain_form.fields.released=Released
|
||||||
|
ui.admin.categories.domain_form.errors.domain_key_blank=The key of a domain can't be blank.
|
||||||
|
ui.admin.categories.domain_form.errors.version_blank=The version of domain can't be blank.
|
||||||
|
ui.admin.categories.domain_form.fields.root_category_name=Name of root category
|
||||||
|
|
|
||||||
|
|
@ -361,3 +361,6 @@ ui.admin.categories.domain_form.fields.domain_key=Name
|
||||||
ui.admin.categories.domain_form.fields.domain_uri=URI
|
ui.admin.categories.domain_form.fields.domain_uri=URI
|
||||||
ui.admin.categories.domain_form.fields.version=Version
|
ui.admin.categories.domain_form.fields.version=Version
|
||||||
ui.admin.categories.domain_form.fields.released=Freigegeben
|
ui.admin.categories.domain_form.fields.released=Freigegeben
|
||||||
|
ui.admin.categories.domain_form.errors.domain_key_blank=Der Key einer Domain darf nicht leer sein.
|
||||||
|
ui.admin.categories.domain_form.errors.version_blank=Die Version einer Domain darf nicht leer sein.
|
||||||
|
ui.admin.categories.domain_form.fields.root_category_name=Name der Wurzelkategorie
|
||||||
|
|
|
||||||
|
|
@ -334,3 +334,6 @@ ui.admin.categories.domain_form.fields.domain_key=Key
|
||||||
ui.admin.categories.domain_form.fields.domain_uri=URI
|
ui.admin.categories.domain_form.fields.domain_uri=URI
|
||||||
ui.admin.categories.domain_form.fields.version=Version
|
ui.admin.categories.domain_form.fields.version=Version
|
||||||
ui.admin.categories.domain_form.fields.released=Released
|
ui.admin.categories.domain_form.fields.released=Released
|
||||||
|
ui.admin.categories.domain_form.errors.domain_key_blank=The key of a domain can't be blank.
|
||||||
|
ui.admin.categories.domain_form.errors.version_blank=The version of domain can't be blank.
|
||||||
|
ui.admin.categories.domain_form.fields.root_category_name=Name of root category
|
||||||
|
|
|
||||||
|
|
@ -325,3 +325,6 @@ ui.admin.categories.domain_form.fields.domain_key=Key
|
||||||
ui.admin.categories.domain_form.fields.domain_uri=URI
|
ui.admin.categories.domain_form.fields.domain_uri=URI
|
||||||
ui.admin.categories.domain_form.fields.version=Version
|
ui.admin.categories.domain_form.fields.version=Version
|
||||||
ui.admin.categories.domain_form.fields.released=Released
|
ui.admin.categories.domain_form.fields.released=Released
|
||||||
|
ui.admin.categories.domain_form.errors.domain_key_blank=The key of a domain can't be blank.
|
||||||
|
ui.admin.categories.domain_form.errors.version_blank=The version of domain can't be blank.
|
||||||
|
ui.admin.categories.domain_form.fields.root_category_name=Name of root category
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue