Controller for managing LifecyclesDefinitions

Former-commit-id: bc93d8f5d11b62f33536bd03dcb08f4642d4492d
pull/10/head
Jens Pelzetter 2021-03-03 21:00:02 +01:00
parent 71f3c07d41
commit 04c7de59d0
5 changed files with 1022 additions and 26 deletions

View File

@ -0,0 +1,54 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.librecms.contentsection;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public class LifecycleDefinitionListModel {
private long definitionId;
private String uuid;
private String label;
private String description;
public long getDefinitionId() {
return definitionId;
}
public void setDefinitionId(final long definitionId) {
this.definitionId = definitionId;
}
public String getUuid() {
return uuid;
}
public void setUuid(final String uuid) {
this.uuid = uuid;
}
public String getLabel() {
return label;
}
public void setLabel(final String label) {
this.label = label;
}
public String getDescription() {
return description;
}
public void setDescription(final String description) {
this.description = description;
}
}

View File

@ -5,10 +5,27 @@
*/ */
package org.librecms.ui.contentsections; package org.librecms.ui.contentsections;
import org.libreccm.api.Identifier;
import org.libreccm.api.IdentifierParser;
import org.libreccm.l10n.GlobalizationHelper;
import org.libreccm.security.AuthorizationRequired; import org.libreccm.security.AuthorizationRequired;
import org.librecms.contentsection.ContentSection;
import org.librecms.contentsection.ContentSectionManager;
import org.librecms.contentsection.LifecycleDefinitionListModel;
import org.librecms.lifecycle.LifecycleDefinition;
import org.librecms.lifecycle.LifecycleDefinitionRepository;
import org.librecms.lifecycle.LifecycleManager;
import org.librecms.lifecycle.PhaseDefinition;
import org.librecms.lifecycle.PhaseDefinititionRepository;
import java.util.Locale;
import java.util.Optional;
import java.util.stream.Collectors;
import javax.enterprise.context.RequestScoped; import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.mvc.Controller; import javax.mvc.Controller;
import javax.mvc.Models;
import javax.transaction.Transactional; import javax.transaction.Transactional;
import javax.ws.rs.FormParam; import javax.ws.rs.FormParam;
import javax.ws.rs.GET; import javax.ws.rs.GET;
@ -25,6 +42,36 @@ import javax.ws.rs.PathParam;
@Path("/{sectionIdentifier}/configuration/lifecycles") @Path("/{sectionIdentifier}/configuration/lifecycles")
public class ConfigurationLifecyclesController { public class ConfigurationLifecyclesController {
@Inject
private AdminPermissionsChecker adminPermissionsChecker;
@Inject
private ContentSectionManager sectionManager;
@Inject
private ContentSectionsUi sectionsUi;
@Inject
private GlobalizationHelper globalizationHelper;
@Inject
private IdentifierParser identifierParser;
@Inject
private LifecycleManager lifecycleManager;
@Inject
private LifecycleDefinitionRepository definitionRepo;
@Inject
private Models models;
@Inject
private PhaseDefinititionRepository phaseDefinititionRepo;
@Inject
private SelectedLifecycleDefinitionModel selectedDefinitionModel;
@GET @GET
@Path("/") @Path("/")
@AuthorizationRequired @AuthorizationRequired
@ -32,7 +79,27 @@ public class ConfigurationLifecyclesController {
public String listLifecycleDefinitions( public String listLifecycleDefinitions(
@PathParam("sectionIdentifier") final String sectionIdentifierParam @PathParam("sectionIdentifier") final String sectionIdentifierParam
) { ) {
throw new UnsupportedOperationException("Not implemented yet."); final Optional<ContentSection> sectionResult = sectionsUi
.findContentSection(sectionIdentifierParam);
if (!sectionResult.isPresent()) {
sectionsUi.showContentSectionNotFound(sectionIdentifierParam);
}
final ContentSection section = sectionResult.get();
if (!adminPermissionsChecker.canAdministerLifecycles(section)) {
return sectionsUi.showAccessDenied(
"sectionIdentifier", sectionIdentifierParam
);
}
models.put(
"lifecycleDefinitions",
section
.getLifecycleDefinitions()
.stream()
.map(this::buildListModel)
.collect(Collectors.toList())
);
return "org/librecms/ui/contentsection/configuration/lifecycles.xhtml";
} }
@GET @GET
@ -43,7 +110,62 @@ public class ConfigurationLifecyclesController {
@PathParam("sectionIdentifier") final String sectionIdentifierParam, @PathParam("sectionIdentifier") final String sectionIdentifierParam,
@PathParam("lifecycleIdentifier") final String lifecycleIdentiferParam @PathParam("lifecycleIdentifier") final String lifecycleIdentiferParam
) { ) {
throw new UnsupportedOperationException("Not implemented yet."); final Optional<ContentSection> sectionResult = sectionsUi
.findContentSection(sectionIdentifierParam);
if (!sectionResult.isPresent()) {
sectionsUi.showContentSectionNotFound(sectionIdentifierParam);
}
final ContentSection section = sectionResult.get();
if (!adminPermissionsChecker.canAdministerLifecycles(section)) {
return sectionsUi.showAccessDenied(
"sectionIdentifier", sectionIdentifierParam
);
}
final Optional<LifecycleDefinition> definitionResult
= findLifecycleDefinition(section, sectionIdentifierParam);
if (!definitionResult.isPresent()) {
return showLifecycleDefinitionNotFound(
section, sectionIdentifierParam
);
}
final LifecycleDefinition definition = definitionResult.get();
selectedDefinitionModel.setUuid(definition.getUuid());
selectedDefinitionModel.setLabel(
definition
.getLabel()
.getValues()
.entrySet()
.stream()
.collect(
Collectors.toMap(
entry -> entry.getKey().toString(),
entry -> entry.getValue()
)
)
);
selectedDefinitionModel.setDescription(
definition
.getDescription()
.getValues()
.entrySet()
.stream()
.collect(
Collectors.toMap(
entry -> entry.getKey().toString(),
entry -> entry.getValue()
)
)
);
selectedDefinitionModel.setPhaseDefinitions(
definition
.getPhaseDefinitions()
.stream()
.map(this::buildPhaseDefinitionModel)
.collect(Collectors.toList())
);
return "org/librecms/ui/contentsection/configuration/lifecycle.xhtml";
} }
@POST @POST
@ -53,7 +175,29 @@ public class ConfigurationLifecyclesController {
@PathParam("sectionIdentifier") final String sectionIdentifierParam, @PathParam("sectionIdentifier") final String sectionIdentifierParam,
@FormParam("label") final String label @FormParam("label") final String label
) { ) {
throw new UnsupportedOperationException("Not implemented yet."); final Optional<ContentSection> sectionResult = sectionsUi
.findContentSection(sectionIdentifierParam);
if (!sectionResult.isPresent()) {
sectionsUi.showContentSectionNotFound(sectionIdentifierParam);
}
final ContentSection section = sectionResult.get();
if (!adminPermissionsChecker.canAdministerLifecycles(section)) {
return sectionsUi.showAccessDenied(
"sectionIdentifier", sectionIdentifierParam
);
}
final LifecycleDefinition definition = new LifecycleDefinition();
definition
.getLabel()
.addValue(globalizationHelper.getNegotiatedLocale(), label);
sectionManager.addLifecycleDefinitionToContentSection(
definition, section
);
return String.format(
"redirect:/%s/configuration/lifecycles", sectionIdentifierParam
);
} }
@POST @POST
@ -64,7 +208,34 @@ public class ConfigurationLifecyclesController {
@PathParam("sectionIdentifier") final String sectionIdentifierParam, @PathParam("sectionIdentifier") final String sectionIdentifierParam,
@PathParam("lifecycleIdentifier") final String lifecycleIdentiferParam @PathParam("lifecycleIdentifier") final String lifecycleIdentiferParam
) { ) {
throw new UnsupportedOperationException("Not implemented yet."); final Optional<ContentSection> sectionResult = sectionsUi
.findContentSection(sectionIdentifierParam);
if (!sectionResult.isPresent()) {
sectionsUi.showContentSectionNotFound(sectionIdentifierParam);
}
final ContentSection section = sectionResult.get();
if (!adminPermissionsChecker.canAdministerLifecycles(section)) {
return sectionsUi.showAccessDenied(
"sectionIdentifier", sectionIdentifierParam
);
}
final Optional<LifecycleDefinition> definitionResult
= findLifecycleDefinition(section, sectionIdentifierParam);
if (!definitionResult.isPresent()) {
return showLifecycleDefinitionNotFound(
section, sectionIdentifierParam
);
}
final LifecycleDefinition definition = definitionResult.get();
sectionManager.removeLifecycleDefinitionFromContentSection(
definition, section
);
definitionRepo.delete(definition);
return String.format(
"redirect:/%s/configuration/lifecycles", sectionIdentifierParam
);
} }
@POST @POST
@ -77,7 +248,34 @@ public class ConfigurationLifecyclesController {
@FormParam("locale") final String localeParam, @FormParam("locale") final String localeParam,
@FormParam("value") final String value @FormParam("value") final String value
) { ) {
throw new UnsupportedOperationException("Not implemented yet."); final Optional<ContentSection> sectionResult = sectionsUi
.findContentSection(sectionIdentifierParam);
if (!sectionResult.isPresent()) {
sectionsUi.showContentSectionNotFound(sectionIdentifierParam);
}
final ContentSection section = sectionResult.get();
if (!adminPermissionsChecker.canAdministerLifecycles(section)) {
return sectionsUi.showAccessDenied(
"sectionIdentifier", sectionIdentifierParam
);
}
final Optional<LifecycleDefinition> definitionResult
= findLifecycleDefinition(section, sectionIdentifierParam);
if (!definitionResult.isPresent()) {
return showLifecycleDefinitionNotFound(
section, sectionIdentifierParam
);
}
final LifecycleDefinition definition = definitionResult.get();
definition.getLabel().addValue(new Locale(localeParam), value);
definitionRepo.save(definition);
return String.format(
"redirect:/%s/configuration/lifecycles/%s",
sectionIdentifierParam,
lifecycleIdentiferParam
);
} }
@POST @POST
@ -90,7 +288,34 @@ public class ConfigurationLifecyclesController {
@PathParam("locale") final String localeParam, @PathParam("locale") final String localeParam,
@FormParam("value") final String value @FormParam("value") final String value
) { ) {
throw new UnsupportedOperationException("Not implemented yet."); final Optional<ContentSection> sectionResult = sectionsUi
.findContentSection(sectionIdentifierParam);
if (!sectionResult.isPresent()) {
sectionsUi.showContentSectionNotFound(sectionIdentifierParam);
}
final ContentSection section = sectionResult.get();
if (!adminPermissionsChecker.canAdministerLifecycles(section)) {
return sectionsUi.showAccessDenied(
"sectionIdentifier", sectionIdentifierParam
);
}
final Optional<LifecycleDefinition> definitionResult
= findLifecycleDefinition(section, sectionIdentifierParam);
if (!definitionResult.isPresent()) {
return showLifecycleDefinitionNotFound(
section, sectionIdentifierParam
);
}
final LifecycleDefinition definition = definitionResult.get();
definition.getLabel().addValue(new Locale(localeParam), value);
definitionRepo.save(definition);
return String.format(
"redirect:/%s/configuration/lifecycles/%s",
sectionIdentifierParam,
lifecycleIdentiferParam
);
} }
@POST @POST
@ -100,10 +325,36 @@ public class ConfigurationLifecyclesController {
public String removeLifecycleDefinitionLabel( public String removeLifecycleDefinitionLabel(
@PathParam("sectionIdentifier") final String sectionIdentifierParam, @PathParam("sectionIdentifier") final String sectionIdentifierParam,
@PathParam("lifecycleIdentifier") final String lifecycleIdentiferParam, @PathParam("lifecycleIdentifier") final String lifecycleIdentiferParam,
@PathParam("locale") final String localeParam, @PathParam("locale") final String localeParam
@FormParam("value") final String value
) { ) {
throw new UnsupportedOperationException("Not implemented yet."); final Optional<ContentSection> sectionResult = sectionsUi
.findContentSection(sectionIdentifierParam);
if (!sectionResult.isPresent()) {
sectionsUi.showContentSectionNotFound(sectionIdentifierParam);
}
final ContentSection section = sectionResult.get();
if (!adminPermissionsChecker.canAdministerLifecycles(section)) {
return sectionsUi.showAccessDenied(
"sectionIdentifier", sectionIdentifierParam
);
}
final Optional<LifecycleDefinition> definitionResult
= findLifecycleDefinition(section, sectionIdentifierParam);
if (!definitionResult.isPresent()) {
return showLifecycleDefinitionNotFound(
section, sectionIdentifierParam
);
}
final LifecycleDefinition definition = definitionResult.get();
definition.getLabel().removeValue(new Locale(localeParam));
definitionRepo.save(definition);
return String.format(
"redirect:/%s/configuration/lifecycles/%s",
sectionIdentifierParam,
lifecycleIdentiferParam
);
} }
@POST @POST
@ -116,7 +367,34 @@ public class ConfigurationLifecyclesController {
@FormParam("locale") final String localeParam, @FormParam("locale") final String localeParam,
@FormParam("value") final String value @FormParam("value") final String value
) { ) {
throw new UnsupportedOperationException("Not implemented yet."); final Optional<ContentSection> sectionResult = sectionsUi
.findContentSection(sectionIdentifierParam);
if (!sectionResult.isPresent()) {
sectionsUi.showContentSectionNotFound(sectionIdentifierParam);
}
final ContentSection section = sectionResult.get();
if (!adminPermissionsChecker.canAdministerLifecycles(section)) {
return sectionsUi.showAccessDenied(
"sectionIdentifier", sectionIdentifierParam
);
}
final Optional<LifecycleDefinition> definitionResult
= findLifecycleDefinition(section, sectionIdentifierParam);
if (!definitionResult.isPresent()) {
return showLifecycleDefinitionNotFound(
section, sectionIdentifierParam
);
}
final LifecycleDefinition definition = definitionResult.get();
definition.getDescription().addValue(new Locale(localeParam), value);
definitionRepo.save(definition);
return String.format(
"redirect:/%s/configuration/lifecycles/%s",
sectionIdentifierParam,
lifecycleIdentiferParam
);
} }
@POST @POST
@ -129,7 +407,34 @@ public class ConfigurationLifecyclesController {
@PathParam("locale") final String localeParam, @PathParam("locale") final String localeParam,
@FormParam("value") final String value @FormParam("value") final String value
) { ) {
throw new UnsupportedOperationException("Not implemented yet."); final Optional<ContentSection> sectionResult = sectionsUi
.findContentSection(sectionIdentifierParam);
if (!sectionResult.isPresent()) {
sectionsUi.showContentSectionNotFound(sectionIdentifierParam);
}
final ContentSection section = sectionResult.get();
if (!adminPermissionsChecker.canAdministerLifecycles(section)) {
return sectionsUi.showAccessDenied(
"sectionIdentifier", sectionIdentifierParam
);
}
final Optional<LifecycleDefinition> definitionResult
= findLifecycleDefinition(section, sectionIdentifierParam);
if (!definitionResult.isPresent()) {
return showLifecycleDefinitionNotFound(
section, sectionIdentifierParam
);
}
final LifecycleDefinition definition = definitionResult.get();
definition.getDescription().addValue(new Locale(localeParam), value);
definitionRepo.save(definition);
return String.format(
"redirect:/%s/configuration/lifecycles/%s",
sectionIdentifierParam,
lifecycleIdentiferParam
);
} }
@POST @POST
@ -139,10 +444,36 @@ public class ConfigurationLifecyclesController {
public String removeLifecycleDefinitionDescription( public String removeLifecycleDefinitionDescription(
@PathParam("sectionIdentifier") final String sectionIdentifierParam, @PathParam("sectionIdentifier") final String sectionIdentifierParam,
@PathParam("lifecycleIdentifier") final String lifecycleIdentiferParam, @PathParam("lifecycleIdentifier") final String lifecycleIdentiferParam,
@PathParam("locale") final String localeParam, @PathParam("locale") final String localeParam
@FormParam("value") final String value
) { ) {
throw new UnsupportedOperationException("Not implemented yet."); final Optional<ContentSection> sectionResult = sectionsUi
.findContentSection(sectionIdentifierParam);
if (!sectionResult.isPresent()) {
sectionsUi.showContentSectionNotFound(sectionIdentifierParam);
}
final ContentSection section = sectionResult.get();
if (!adminPermissionsChecker.canAdministerLifecycles(section)) {
return sectionsUi.showAccessDenied(
"sectionIdentifier", sectionIdentifierParam
);
}
final Optional<LifecycleDefinition> definitionResult
= findLifecycleDefinition(section, sectionIdentifierParam);
if (!definitionResult.isPresent()) {
return showLifecycleDefinitionNotFound(
section, sectionIdentifierParam
);
}
final LifecycleDefinition definition = definitionResult.get();
definition.getDescription().removeValue(new Locale(localeParam));
definitionRepo.save(definition);
return String.format(
"redirect:/%s/configuration/lifecycles/%s",
sectionIdentifierParam,
lifecycleIdentiferParam
);
} }
@POST @POST
@ -156,7 +487,40 @@ public class ConfigurationLifecyclesController {
@FormParam("defaultDelay") final long defaultDelay, @FormParam("defaultDelay") final long defaultDelay,
@FormParam("defaultDuration") final long defaultDuration @FormParam("defaultDuration") final long defaultDuration
) { ) {
throw new UnsupportedOperationException("Not implemented yet."); final Optional<ContentSection> sectionResult = sectionsUi
.findContentSection(sectionIdentifierParam);
if (!sectionResult.isPresent()) {
sectionsUi.showContentSectionNotFound(sectionIdentifierParam);
}
final ContentSection section = sectionResult.get();
if (!adminPermissionsChecker.canAdministerLifecycles(section)) {
return sectionsUi.showAccessDenied(
"sectionIdentifier", sectionIdentifierParam
);
}
final Optional<LifecycleDefinition> definitionResult
= findLifecycleDefinition(section, sectionIdentifierParam);
if (!definitionResult.isPresent()) {
return showLifecycleDefinitionNotFound(
section, sectionIdentifierParam
);
}
final LifecycleDefinition definition = definitionResult.get();
final PhaseDefinition phaseDefinition = new PhaseDefinition();
phaseDefinition.setDefaultDelay(defaultDelay);
phaseDefinition.setDefaultDuration(defaultDuration);
phaseDefinition
.getLabel()
.addValue(globalizationHelper.getNegotiatedLocale(), label);
lifecycleManager.addPhaseDefinition(definition, phaseDefinition);
return String.format(
"redirect:/%s/configuration/lifecycles/%s",
sectionIdentifierParam,
lifecycleIdentiferParam
);
} }
@POST @POST
@ -170,7 +534,46 @@ public class ConfigurationLifecyclesController {
@FormParam("defaultDelay") final long defaultDelay, @FormParam("defaultDelay") final long defaultDelay,
@FormParam("defaultDuration") final long defaultDuration @FormParam("defaultDuration") final long defaultDuration
) { ) {
throw new UnsupportedOperationException("Not implemented yet."); final Optional<ContentSection> sectionResult = sectionsUi
.findContentSection(sectionIdentifierParam);
if (!sectionResult.isPresent()) {
sectionsUi.showContentSectionNotFound(sectionIdentifierParam);
}
final ContentSection section = sectionResult.get();
if (!adminPermissionsChecker.canAdministerLifecycles(section)) {
return sectionsUi.showAccessDenied(
"sectionIdentifier", sectionIdentifierParam
);
}
final Optional<LifecycleDefinition> definitionResult
= findLifecycleDefinition(section, sectionIdentifierParam);
if (!definitionResult.isPresent()) {
return showLifecycleDefinitionNotFound(
section, sectionIdentifierParam
);
}
final LifecycleDefinition definition = definitionResult.get();
final Optional<PhaseDefinition> phaseDefinitionResult
= findPhaseDefinition(definition, sectionIdentifierParam);
if (!phaseDefinitionResult.isPresent()) {
return showPhaseDefinitionNotFound(
section,
sectionIdentifierParam,
phaseIdentifierParam
);
}
final PhaseDefinition phaseDefinition = phaseDefinitionResult.get();
phaseDefinition.setDefaultDelay(defaultDelay);
phaseDefinition.setDefaultDuration(defaultDuration);
phaseDefinititionRepo.save(phaseDefinition);
return String.format(
"redirect:/%s/configuration/lifecycles/%s",
sectionIdentifierParam,
lifecycleIdentiferParam
);
} }
@POST @POST
@ -182,7 +585,44 @@ public class ConfigurationLifecyclesController {
@PathParam("lifecycleIdentifier") final String lifecycleIdentiferParam, @PathParam("lifecycleIdentifier") final String lifecycleIdentiferParam,
@PathParam("phaseIdentifier") final String phaseIdentifierParam @PathParam("phaseIdentifier") final String phaseIdentifierParam
) { ) {
throw new UnsupportedOperationException("Not implemented yet."); final Optional<ContentSection> sectionResult = sectionsUi
.findContentSection(sectionIdentifierParam);
if (!sectionResult.isPresent()) {
sectionsUi.showContentSectionNotFound(sectionIdentifierParam);
}
final ContentSection section = sectionResult.get();
if (!adminPermissionsChecker.canAdministerLifecycles(section)) {
return sectionsUi.showAccessDenied(
"sectionIdentifier", sectionIdentifierParam
);
}
final Optional<LifecycleDefinition> definitionResult
= findLifecycleDefinition(section, sectionIdentifierParam);
if (!definitionResult.isPresent()) {
return showLifecycleDefinitionNotFound(
section, sectionIdentifierParam
);
}
final LifecycleDefinition definition = definitionResult.get();
final Optional<PhaseDefinition> phaseDefinitionResult
= findPhaseDefinition(definition, sectionIdentifierParam);
if (!phaseDefinitionResult.isPresent()) {
return showPhaseDefinitionNotFound(
section,
sectionIdentifierParam,
phaseIdentifierParam
);
}
final PhaseDefinition phaseDefinition = phaseDefinitionResult.get();
lifecycleManager.removePhaseDefinition(definition, phaseDefinition);
phaseDefinititionRepo.delete(phaseDefinition);
return String.format(
"redirect:/%s/configuration/lifecycles/%s",
sectionIdentifierParam,
lifecycleIdentiferParam
);
} }
@POST @POST
@ -196,7 +636,44 @@ public class ConfigurationLifecyclesController {
@FormParam("locale") final String localeParam, @FormParam("locale") final String localeParam,
@FormParam("value") final String value @FormParam("value") final String value
) { ) {
throw new UnsupportedOperationException("Not implemented yet."); final Optional<ContentSection> sectionResult = sectionsUi
.findContentSection(sectionIdentifierParam);
if (!sectionResult.isPresent()) {
sectionsUi.showContentSectionNotFound(sectionIdentifierParam);
}
final ContentSection section = sectionResult.get();
if (!adminPermissionsChecker.canAdministerLifecycles(section)) {
return sectionsUi.showAccessDenied(
"sectionIdentifier", sectionIdentifierParam
);
}
final Optional<LifecycleDefinition> definitionResult
= findLifecycleDefinition(section, sectionIdentifierParam);
if (!definitionResult.isPresent()) {
return showLifecycleDefinitionNotFound(
section, sectionIdentifierParam
);
}
final LifecycleDefinition definition = definitionResult.get();
final Optional<PhaseDefinition> phaseDefinitionResult
= findPhaseDefinition(definition, sectionIdentifierParam);
if (!phaseDefinitionResult.isPresent()) {
return showPhaseDefinitionNotFound(
section,
sectionIdentifierParam,
phaseIdentifierParam
);
}
final PhaseDefinition phaseDefinition = phaseDefinitionResult.get();
phaseDefinition.getLabel().addValue(new Locale(localeParam), value);
phaseDefinititionRepo.save(phaseDefinition);
return String.format(
"redirect:/%s/configuration/lifecycles/%s",
sectionIdentifierParam,
lifecycleIdentiferParam
);
} }
@POST @POST
@ -210,7 +687,44 @@ public class ConfigurationLifecyclesController {
@PathParam("locale") final String localeParam, @PathParam("locale") final String localeParam,
@FormParam("value") final String value @FormParam("value") final String value
) { ) {
throw new UnsupportedOperationException("Not implemented yet."); final Optional<ContentSection> sectionResult = sectionsUi
.findContentSection(sectionIdentifierParam);
if (!sectionResult.isPresent()) {
sectionsUi.showContentSectionNotFound(sectionIdentifierParam);
}
final ContentSection section = sectionResult.get();
if (!adminPermissionsChecker.canAdministerLifecycles(section)) {
return sectionsUi.showAccessDenied(
"sectionIdentifier", sectionIdentifierParam
);
}
final Optional<LifecycleDefinition> definitionResult
= findLifecycleDefinition(section, sectionIdentifierParam);
if (!definitionResult.isPresent()) {
return showLifecycleDefinitionNotFound(
section, sectionIdentifierParam
);
}
final LifecycleDefinition definition = definitionResult.get();
final Optional<PhaseDefinition> phaseDefinitionResult
= findPhaseDefinition(definition, sectionIdentifierParam);
if (!phaseDefinitionResult.isPresent()) {
return showPhaseDefinitionNotFound(
section,
sectionIdentifierParam,
phaseIdentifierParam
);
}
final PhaseDefinition phaseDefinition = phaseDefinitionResult.get();
phaseDefinition.getLabel().addValue(new Locale(localeParam), value);
phaseDefinititionRepo.save(phaseDefinition);
return String.format(
"redirect:/%s/configuration/lifecycles/%s",
sectionIdentifierParam,
lifecycleIdentiferParam
);
} }
@POST @POST
@ -224,7 +738,44 @@ public class ConfigurationLifecyclesController {
@PathParam("phaseIdentifier") final String phaseIdentifierParam, @PathParam("phaseIdentifier") final String phaseIdentifierParam,
@PathParam("locale") final String localeParam @PathParam("locale") final String localeParam
) { ) {
throw new UnsupportedOperationException("Not implemented yet."); final Optional<ContentSection> sectionResult = sectionsUi
.findContentSection(sectionIdentifierParam);
if (!sectionResult.isPresent()) {
sectionsUi.showContentSectionNotFound(sectionIdentifierParam);
}
final ContentSection section = sectionResult.get();
if (!adminPermissionsChecker.canAdministerLifecycles(section)) {
return sectionsUi.showAccessDenied(
"sectionIdentifier", sectionIdentifierParam
);
}
final Optional<LifecycleDefinition> definitionResult
= findLifecycleDefinition(section, sectionIdentifierParam);
if (!definitionResult.isPresent()) {
return showLifecycleDefinitionNotFound(
section, sectionIdentifierParam
);
}
final LifecycleDefinition definition = definitionResult.get();
final Optional<PhaseDefinition> phaseDefinitionResult
= findPhaseDefinition(definition, sectionIdentifierParam);
if (!phaseDefinitionResult.isPresent()) {
return showPhaseDefinitionNotFound(
section,
sectionIdentifierParam,
phaseIdentifierParam
);
}
final PhaseDefinition phaseDefinition = phaseDefinitionResult.get();
phaseDefinition.getLabel().removeValue(new Locale(localeParam));
phaseDefinititionRepo.save(phaseDefinition);
return String.format(
"redirect:/%s/configuration/lifecycles/%s",
sectionIdentifierParam,
lifecycleIdentiferParam
);
} }
@POST @POST
@ -238,7 +789,46 @@ public class ConfigurationLifecyclesController {
@FormParam("locale") final String localeParam, @FormParam("locale") final String localeParam,
@FormParam("value") final String value @FormParam("value") final String value
) { ) {
throw new UnsupportedOperationException("Not implemented yet."); final Optional<ContentSection> sectionResult = sectionsUi
.findContentSection(sectionIdentifierParam);
if (!sectionResult.isPresent()) {
sectionsUi.showContentSectionNotFound(sectionIdentifierParam);
}
final ContentSection section = sectionResult.get();
if (!adminPermissionsChecker.canAdministerLifecycles(section)) {
return sectionsUi.showAccessDenied(
"sectionIdentifier", sectionIdentifierParam
);
}
final Optional<LifecycleDefinition> definitionResult
= findLifecycleDefinition(section, sectionIdentifierParam);
if (!definitionResult.isPresent()) {
return showLifecycleDefinitionNotFound(
section, sectionIdentifierParam
);
}
final LifecycleDefinition definition = definitionResult.get();
final Optional<PhaseDefinition> phaseDefinitionResult
= findPhaseDefinition(definition, sectionIdentifierParam);
if (!phaseDefinitionResult.isPresent()) {
return showPhaseDefinitionNotFound(
section,
sectionIdentifierParam,
phaseIdentifierParam
);
}
final PhaseDefinition phaseDefinition = phaseDefinitionResult.get();
phaseDefinition.getDescription().addValue(
new Locale(localeParam), value
);
phaseDefinititionRepo.save(phaseDefinition);
return String.format(
"redirect:/%s/configuration/lifecycles/%s",
sectionIdentifierParam,
lifecycleIdentiferParam
);
} }
@POST @POST
@ -253,7 +843,46 @@ public class ConfigurationLifecyclesController {
@PathParam("locale") final String localeParam, @PathParam("locale") final String localeParam,
@FormParam("value") final String value @FormParam("value") final String value
) { ) {
throw new UnsupportedOperationException("Not implemented yet."); final Optional<ContentSection> sectionResult = sectionsUi
.findContentSection(sectionIdentifierParam);
if (!sectionResult.isPresent()) {
sectionsUi.showContentSectionNotFound(sectionIdentifierParam);
}
final ContentSection section = sectionResult.get();
if (!adminPermissionsChecker.canAdministerLifecycles(section)) {
return sectionsUi.showAccessDenied(
"sectionIdentifier", sectionIdentifierParam
);
}
final Optional<LifecycleDefinition> definitionResult
= findLifecycleDefinition(section, sectionIdentifierParam);
if (!definitionResult.isPresent()) {
return showLifecycleDefinitionNotFound(
section, sectionIdentifierParam
);
}
final LifecycleDefinition definition = definitionResult.get();
final Optional<PhaseDefinition> phaseDefinitionResult
= findPhaseDefinition(definition, sectionIdentifierParam);
if (!phaseDefinitionResult.isPresent()) {
return showPhaseDefinitionNotFound(
section,
sectionIdentifierParam,
phaseIdentifierParam
);
}
final PhaseDefinition phaseDefinition = phaseDefinitionResult.get();
phaseDefinition.getDescription().addValue(
new Locale(localeParam), value
);
phaseDefinititionRepo.save(phaseDefinition);
return String.format(
"redirect:/%s/configuration/lifecycles/%s",
sectionIdentifierParam,
lifecycleIdentiferParam
);
} }
@POST @POST
@ -267,7 +896,167 @@ public class ConfigurationLifecyclesController {
@PathParam("phaseIdentifier") final String phaseIdentifierParam, @PathParam("phaseIdentifier") final String phaseIdentifierParam,
@PathParam("locale") final String localeParam @PathParam("locale") final String localeParam
) { ) {
throw new UnsupportedOperationException("Not implemented yet."); final Optional<ContentSection> sectionResult = sectionsUi
.findContentSection(sectionIdentifierParam);
if (!sectionResult.isPresent()) {
sectionsUi.showContentSectionNotFound(sectionIdentifierParam);
}
final ContentSection section = sectionResult.get();
if (!adminPermissionsChecker.canAdministerLifecycles(section)) {
return sectionsUi.showAccessDenied(
"sectionIdentifier", sectionIdentifierParam
);
}
final Optional<LifecycleDefinition> definitionResult
= findLifecycleDefinition(section, sectionIdentifierParam);
if (!definitionResult.isPresent()) {
return showLifecycleDefinitionNotFound(
section, sectionIdentifierParam
);
}
final LifecycleDefinition definition = definitionResult.get();
final Optional<PhaseDefinition> phaseDefinitionResult
= findPhaseDefinition(definition, sectionIdentifierParam);
if (!phaseDefinitionResult.isPresent()) {
return showPhaseDefinitionNotFound(
section,
sectionIdentifierParam,
phaseIdentifierParam
);
}
final PhaseDefinition phaseDefinition = phaseDefinitionResult.get();
phaseDefinition.getDescription().removeValue(new Locale(localeParam));
phaseDefinititionRepo.save(phaseDefinition);
return String.format(
"redirect:/%s/configuration/lifecycles/%s",
sectionIdentifierParam,
lifecycleIdentiferParam
);
}
private LifecycleDefinitionListModel buildListModel(
final LifecycleDefinition definition
) {
final LifecycleDefinitionListModel model
= new LifecycleDefinitionListModel();
model.setDefinitionId(definition.getDefinitionId());
model.setUuid(definition.getUuid());
model.setLabel(
globalizationHelper.getValueFromLocalizedString(
definition.getLabel()
)
);
model.setDescription(
globalizationHelper.getValueFromLocalizedString(
definition.getDescription()
)
);
return model;
}
private Optional<LifecycleDefinition> findLifecycleDefinition(
final ContentSection section, final String definitionIdentifierParam
) {
final Identifier identifier = identifierParser.parseIdentifier(
definitionIdentifierParam
);
switch (identifier.getType()) {
case ID:
return section
.getLifecycleDefinitions()
.stream()
.filter(
definition -> definition.getDefinitionId() == Long
.parseLong(identifier.getIdentifier())
).findAny();
default:
return section
.getLifecycleDefinitions()
.stream()
.filter(
definition -> definition.getUuid().equals(identifier
.getIdentifier())
).findAny();
}
}
private String showLifecycleDefinitionNotFound(
final ContentSection section,
final String definitionIdentifier
) {
models.put("sectionIdentifier", section.getLabel());
models.put("definitionIdentifier", definitionIdentifier);
return "org/librecms/ui/contentsection/configuration/lifecycle-not-found.xhtml";
}
private PhaseDefinitionModel buildPhaseDefinitionModel(
final PhaseDefinition definition
) {
final PhaseDefinitionModel model = new PhaseDefinitionModel();
model.setDefaultDelay(definition.getDefaultDelay());
model.setDefaultDuration(definition.getDefaultDuration());
model.setDefinitionId(definition.getDefinitionId());
model.setDescription(
definition
.getDescription()
.getValues()
.entrySet()
.stream()
.collect(
Collectors.toMap(
entry -> entry.getKey().toString(),
entry -> entry.getValue()
)
)
);
model.setDisplayDescription(
globalizationHelper
.getValueFromLocalizedString(definition.getDescription())
);
model.setDisplayLabel(
globalizationHelper
.getValueFromLocalizedString(definition.getLabel())
);
model.setLabel(
definition
.getLabel()
.getValues()
.entrySet()
.stream()
.collect(
Collectors.toMap(
entry -> entry.getKey().toString(),
entry -> entry.getValue()
)
)
);
return model;
}
private Optional<PhaseDefinition> findPhaseDefinition(
final LifecycleDefinition lifecycleDefinition,
final String phaseDefinitionIdentifierParam
) {
return lifecycleDefinition
.getPhaseDefinitions()
.stream()
.filter(
definition -> definition.getDefinitionId() == Long
.parseLong(phaseDefinitionIdentifierParam)
).findAny();
}
private String showPhaseDefinitionNotFound(
final ContentSection section,
final String definitionIdentifier,
final String phaseDefinitionIdentifier
) {
models.put("sectionIdentifier", section.getLabel());
models.put("lifecycleDefinitionIdentifier", definitionIdentifier);
models.put("phaseDefinitionIdentifier", phaseDefinitionIdentifier);
return "org/librecms/ui/contentsection/configuration/lifecyclephase-not-found.xhtml";
} }
} }

View File

@ -122,7 +122,6 @@ public class ConfigurationRolesController {
} }
final List<Role> sectionRoles = section.getRoles(); final List<Role> sectionRoles = section.getRoles();
final Set<Role> otherRoles = roleRepo final Set<Role> otherRoles = roleRepo
.findAll() .findAll()
.stream() .stream()
@ -509,8 +508,7 @@ public class ConfigurationRolesController {
public String removeDescription( public String removeDescription(
@PathParam("sectionIdentifier") final String sectionIdentifierParam, @PathParam("sectionIdentifier") final String sectionIdentifierParam,
@PathParam("roleName") final String roleName, @PathParam("roleName") final String roleName,
@PathParam("locale") final String localeParam, @PathParam("locale") final String localeParam
@FormParam("value") final String value
) { ) {
final Optional<ContentSection> sectionResult = sectionsUi final Optional<ContentSection> sectionResult = sectionsUi
.findContentSection(sectionIdentifierParam); .findContentSection(sectionIdentifierParam);

View File

@ -0,0 +1,88 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.librecms.ui.contentsections;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public class PhaseDefinitionModel {
private long definitionId;
private String displayLabel;
private Map<String, String> label;
private String displayDescription;
private Map<String, String> description;
private long defaultDelay;
private long defaultDuration;
public long getDefinitionId() {
return definitionId;
}
public void setDefinitionId(final long definitionId) {
this.definitionId = definitionId;
}
public String getDisplayLabel() {
return displayLabel;
}
public void setDisplayLabel(final String displayLabel) {
this.displayLabel = displayLabel;
}
public Map<String, String> getLabel() {
return Collections.unmodifiableMap(label);
}
public void setLabel(final Map<String, String> label) {
this.label = new HashMap<>(label);
}
public String getDisplayDescription() {
return displayDescription;
}
public void setDisplayDescription(final String displayDescription) {
this.displayDescription = displayDescription;
}
public Map<String, String> getDescription() {
return Collections.unmodifiableMap(description);
}
public void setDescription(final Map<String, String> description) {
this.description = new HashMap<>(description);
}
public long getDefaultDelay() {
return defaultDelay;
}
public void setDefaultDelay(final long defaultDelay) {
this.defaultDelay = defaultDelay;
}
public long getDefaultDuration() {
return defaultDuration;
}
public void setDefaultDuration(final long defaultDuration) {
this.defaultDuration = defaultDuration;
}
}

View File

@ -0,0 +1,67 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.librecms.ui.contentsections;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.enterprise.context.RequestScoped;
import javax.inject.Named;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@RequestScoped
@Named("SelectedLifecycleModel")
public class SelectedLifecycleDefinitionModel {
private String uuid;
private Map<String, String> label;
private Map<String, String> description;
private List<PhaseDefinitionModel> phaseDefinitions;
public Map<String, String> getLabel() {
return Collections.unmodifiableMap(label);
}
public void setLabel(final Map<String, String> label) {
this.label = new HashMap<>(label);
}
public Map<String, String> getDescription() {
return Collections.unmodifiableMap(description);
}
public void setDescription(final Map<String, String> description) {
this.description = new HashMap<>(description);
}
public List<PhaseDefinitionModel> getPhaseDefinitions() {
return Collections.unmodifiableList(phaseDefinitions);
}
public void setPhaseDefinitions(
final List<PhaseDefinitionModel> phaseDefinitions
) {
this.phaseDefinitions = new ArrayList<>(phaseDefinitions);
}
public String getUuid() {
return uuid;
}
public void setUuid(final String uuid) {
this.uuid = uuid;
}
}