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;
|
||||
|
||||
import com.arsdigita.bebop.Form;
|
||||
import com.arsdigita.bebop.FormData;
|
||||
import com.arsdigita.bebop.Label;
|
||||
import com.arsdigita.bebop.Page;
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
||||
import com.arsdigita.bebop.SaveCancelSection;
|
||||
import com.arsdigita.bebop.form.Date;
|
||||
import com.arsdigita.bebop.form.TextField;
|
||||
import com.arsdigita.globalization.GlobalizedMessage;
|
||||
|
||||
import org.apache.logging.log4j.util.Strings;
|
||||
import org.libreccm.categorization.Domain;
|
||||
import org.libreccm.categorization.DomainManager;
|
||||
import org.libreccm.categorization.DomainRepository;
|
||||
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 DOMAIN_URI = "domainUri";
|
||||
private static final String DOMAIN_KEY = "domainKey";
|
||||
private static final String ROOT_CATEGORY_NAME = "rootCategoryName";
|
||||
|
||||
private final ParameterSingleSelectionModel<String> selectedDomainId;
|
||||
|
||||
|
|
@ -49,11 +55,12 @@ public class DomainForm extends Form {
|
|||
private final TextField domainUri;
|
||||
private final TextField version;
|
||||
private final Date released;
|
||||
private final TextField rootCategoryName;
|
||||
private final SaveCancelSection saveCancelSection;
|
||||
|
||||
public DomainForm(
|
||||
final CategoriesTab categoriesTab,
|
||||
final ParameterSingleSelectionModel<String> selectedDomainId) {
|
||||
final CategoriesTab categoriesTab,
|
||||
final ParameterSingleSelectionModel<String> selectedDomainId) {
|
||||
super("domainForm");
|
||||
|
||||
this.selectedDomainId = selectedDomainId;
|
||||
|
|
@ -63,17 +70,17 @@ public class DomainForm extends Form {
|
|||
final Label target = (Label) e.getTarget();
|
||||
if (selectedDomainId.getSelectedKey(state) == null) {
|
||||
target.setLabel(new GlobalizedMessage(
|
||||
"ui.admin.categories.domain_form.heading.create_new",
|
||||
ADMIN_BUNDLE));
|
||||
"ui.admin.categories.domain_form.heading.create_new",
|
||||
ADMIN_BUNDLE));
|
||||
} else {
|
||||
final DomainRepository domainRepository = CdiUtil.
|
||||
createCdiUtil().findBean(DomainRepository.class);
|
||||
createCdiUtil().findBean(DomainRepository.class);
|
||||
final Domain domain = domainRepository.findById(Long.parseLong(
|
||||
selectedDomainId.getSelectedKey(state)));
|
||||
selectedDomainId.getSelectedKey(state)));
|
||||
target.setLabel(new GlobalizedMessage(
|
||||
"ui.admin.categories.domain_form.heading.edit",
|
||||
ADMIN_BUNDLE,
|
||||
new String[]{domain.getDomainKey()}));
|
||||
"ui.admin.categories.domain_form.heading.edit",
|
||||
ADMIN_BUNDLE,
|
||||
new String[]{domain.getDomainKey()}));
|
||||
}
|
||||
});
|
||||
heading.setClassAttr("heading");
|
||||
|
|
@ -81,40 +88,139 @@ public class DomainForm extends Form {
|
|||
|
||||
domainKey = new TextField(DOMAIN_KEY);
|
||||
domainKey.setLabel(new GlobalizedMessage(
|
||||
"ui.admin.categories.domain_form.fields.domain_key",
|
||||
ADMIN_BUNDLE));
|
||||
"ui.admin.categories.domain_form.fields.domain_key",
|
||||
ADMIN_BUNDLE));
|
||||
add(domainKey);
|
||||
|
||||
domainUri = new TextField(DOMAIN_URI);
|
||||
domainUri.setLabel(new GlobalizedMessage(
|
||||
"ui.admin.categories.domain_form.fields.domain_uri",
|
||||
ADMIN_BUNDLE));
|
||||
"ui.admin.categories.domain_form.fields.domain_uri",
|
||||
ADMIN_BUNDLE));
|
||||
add(domainUri);
|
||||
|
||||
version = new TextField(VERSION);
|
||||
version.setLabel(new GlobalizedMessage(
|
||||
"ui.admin.categories.domain_form.fields.version",
|
||||
ADMIN_BUNDLE));
|
||||
"ui.admin.categories.domain_form.fields.version",
|
||||
ADMIN_BUNDLE));
|
||||
add(version);
|
||||
|
||||
released = new Date(RELEASED);
|
||||
released.setLabel(new GlobalizedMessage(
|
||||
"ui.admin.categories.domain_form.fields.released",
|
||||
ADMIN_BUNDLE));
|
||||
"ui.admin.categories.domain_form.fields.released",
|
||||
ADMIN_BUNDLE));
|
||||
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();
|
||||
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 -> {
|
||||
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 -> {
|
||||
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);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@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(
|
||||
DomainRepository.class);
|
||||
if (Strings.isBlank(filterTerm)) {
|
||||
domains = domainRepository.findAll();
|
||||
domains = domainRepository.findAll("Domain.withOwners");
|
||||
LOGGER.debug("Found {} domains in the database.",
|
||||
domains.size());
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -77,25 +77,34 @@ import javax.xml.bind.annotation.XmlRootElement;
|
|||
query = "SELECT d FROM Domain d WHERE d.domainKey = :key"),
|
||||
@NamedQuery(name = "Domain.findByUri",
|
||||
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(
|
||||
name = "Domain.search",
|
||||
query
|
||||
name = "Domain.search",
|
||||
query
|
||||
= "SELECT d FROM Domain d "
|
||||
+ "WHERE d.domainKey LIKE CONCAT (LOWER(:term), '%') "
|
||||
+ "OR d.uri LIKE CONCAT (LOWER(:term), '%')")
|
||||
+ "WHERE d.domainKey LIKE CONCAT (LOWER(:term), '%') "
|
||||
+ "OR d.uri LIKE CONCAT (LOWER(:term), '%') "
|
||||
+ "ORDER BY d.domainKey")
|
||||
})
|
||||
@NamedEntityGraphs({
|
||||
@NamedEntityGraph(
|
||||
name = "Domain.allCategories",
|
||||
attributeNodes = {
|
||||
@NamedAttributeNode(value = "root",
|
||||
subgraph = "subCategories")},
|
||||
subgraphs = {
|
||||
@NamedSubgraph(
|
||||
name = "subCategories",
|
||||
attributeNodes = {
|
||||
@NamedAttributeNode("subCategories")
|
||||
})})
|
||||
name = "Domain.allCategories",
|
||||
attributeNodes = {
|
||||
@NamedAttributeNode(value = "root",
|
||||
subgraph = "subCategories")},
|
||||
subgraphs = {
|
||||
@NamedSubgraph(
|
||||
name = "subCategories",
|
||||
attributeNodes = {
|
||||
@NamedAttributeNode("subCategories")
|
||||
})}),
|
||||
@NamedEntityGraph(
|
||||
name = "Domain.withOwners",
|
||||
attributeNodes = {
|
||||
@NamedAttributeNode(value = "owners")
|
||||
}
|
||||
)
|
||||
})
|
||||
@DefaultEntityGraph("Domain.allCategories")
|
||||
@XmlRootElement(name = "domain", namespace = CAT_XML_NS)
|
||||
|
|
@ -137,11 +146,11 @@ public class Domain extends CcmObject implements Serializable {
|
|||
*/
|
||||
@Embedded
|
||||
@AssociationOverride(
|
||||
name = "values",
|
||||
joinTable = @JoinTable(name = "DOMAIN_TITLES",
|
||||
schema = DB_SCHEMA,
|
||||
joinColumns = {
|
||||
@JoinColumn(name = "OBJECT_ID")}))
|
||||
name = "values",
|
||||
joinTable = @JoinTable(name = "DOMAIN_TITLES",
|
||||
schema = DB_SCHEMA,
|
||||
joinColumns = {
|
||||
@JoinColumn(name = "OBJECT_ID")}))
|
||||
@XmlElement(name = "title", namespace = CAT_XML_NS)
|
||||
private LocalizedString title;
|
||||
|
||||
|
|
@ -150,11 +159,11 @@ public class Domain extends CcmObject implements Serializable {
|
|||
*/
|
||||
@Embedded
|
||||
@AssociationOverride(
|
||||
name = "values",
|
||||
joinTable = @JoinTable(name = "DOMAIN_DESCRIPTIONS",
|
||||
schema = DB_SCHEMA,
|
||||
joinColumns = {
|
||||
@JoinColumn(name = "OBJECT_ID")}))
|
||||
name = "values",
|
||||
joinTable = @JoinTable(name = "DOMAIN_DESCRIPTIONS",
|
||||
schema = DB_SCHEMA,
|
||||
joinColumns = {
|
||||
@JoinColumn(name = "OBJECT_ID")}))
|
||||
@XmlElement(name = "description", namespace = CAT_XML_NS)
|
||||
private LocalizedString description;
|
||||
|
||||
|
|
@ -369,19 +378,19 @@ public class Domain extends CcmObject implements Serializable {
|
|||
@Override
|
||||
public String toString(final String data) {
|
||||
return String.format(
|
||||
", domainKey = \"%s\", "
|
||||
+ "uri = \"%s\", "
|
||||
+ "title = \"%s\", "
|
||||
+ "version = \"%s\", "
|
||||
+ "released = %tF %<tT, "
|
||||
+ "root = \"%s\"%s",
|
||||
domainKey,
|
||||
Objects.toString(uri),
|
||||
Objects.toString(title),
|
||||
version,
|
||||
released,
|
||||
Objects.toString(root),
|
||||
data
|
||||
", domainKey = \"%s\", "
|
||||
+ "uri = \"%s\", "
|
||||
+ "title = \"%s\", "
|
||||
+ "version = \"%s\", "
|
||||
+ "released = %tF %<tT, "
|
||||
+ "root = \"%s\"%s",
|
||||
domainKey,
|
||||
Objects.toString(uri),
|
||||
Objects.toString(title),
|
||||
version,
|
||||
released,
|
||||
Objects.toString(root),
|
||||
data
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -52,12 +52,13 @@ public class DomainManager {
|
|||
* 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 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 String rootCategoryName) {
|
||||
final Domain domain = new Domain();
|
||||
domain.setDomainKey(domainKey);
|
||||
domain.setVersion("1.0");
|
||||
|
|
@ -81,9 +82,9 @@ public class DomainManager {
|
|||
* {@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}.
|
||||
*/
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public void addDomainOwner(final CcmApplication application,
|
||||
|
|
@ -108,9 +109,9 @@ public class DomainManager {
|
|||
* {@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.
|
||||
* 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) {
|
||||
|
|
@ -122,9 +123,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.
|
||||
* @param domain The {@code Domain} to test.
|
||||
*
|
||||
* @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.
|
||||
*/
|
||||
public boolean isDomainOwner(final CcmApplication application,
|
||||
final Domain domain) {
|
||||
|
|
|
|||
|
|
@ -19,9 +19,11 @@
|
|||
package org.libreccm.categorization;
|
||||
|
||||
import org.libreccm.core.AbstractEntityRepository;
|
||||
import org.libreccm.core.DefaultEntityGraph;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.inject.Inject;
|
||||
|
|
@ -51,6 +53,39 @@ public class DomainRepository extends AbstractEntityRepository<Long, Domain> {
|
|||
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}.
|
||||
*
|
||||
|
|
@ -93,8 +128,11 @@ public class DomainRepository extends AbstractEntityRepository<Long, Domain> {
|
|||
|
||||
public List<Domain> search(final String term) {
|
||||
final TypedQuery<Domain> query = entityManager.createNamedQuery(
|
||||
"Domain.search", Domain.class);
|
||||
"Domain.search", Domain.class);
|
||||
query.setParameter("term", term);
|
||||
final EntityGraph<?> graph = entityManager.getEntityGraph(
|
||||
"Domain.withOwners");
|
||||
query.setHint("javax.persistence.fetchgraph", graph);
|
||||
|
||||
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.version=Version
|
||||
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.version=Version
|
||||
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.version=Version
|
||||
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.version=Version
|
||||
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