DocumentController methods finished
parent
c7a8756c9c
commit
59b4215cd8
|
|
@ -27,10 +27,15 @@ import org.librecms.contentsection.privileges.ItemPrivileges;
|
|||
import org.librecms.lifecycle.LifecycleDefinition;
|
||||
import org.librecms.lifecycle.LifecycleManager;
|
||||
import org.librecms.lifecycle.Phase;
|
||||
import org.librecms.lifecycle.PhaseRepository;
|
||||
import org.librecms.ui.contentsections.ContentSectionsUi;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZoneOffset;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.temporal.TemporalAccessor;
|
||||
import java.util.Date;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
|
@ -92,6 +97,9 @@ public class DocumentController {
|
|||
@Inject
|
||||
private PermissionChecker permissionChecker;
|
||||
|
||||
@Inject
|
||||
private PhaseRepository phaseRepository;
|
||||
|
||||
@Inject
|
||||
private PublishStepModel publishStepModel;
|
||||
|
||||
|
|
@ -358,7 +366,71 @@ public class DocumentController {
|
|||
@FormParam("startDate") final String startDateParam,
|
||||
@FormParam("endDate") final String endDateParam
|
||||
) {
|
||||
throw new UnsupportedOperationException("ToDo");
|
||||
final Optional<ContentSection> sectionResult = sectionsUi
|
||||
.findContentSection(sectionIdentifier);
|
||||
if (!sectionResult.isPresent()) {
|
||||
return sectionsUi.showContentSectionNotFound(sectionIdentifier);
|
||||
}
|
||||
final ContentSection section = sectionResult.get();
|
||||
|
||||
final Optional<ContentItem> itemResult = itemRepo
|
||||
.findByPath(section, documentPath);
|
||||
if (!itemResult.isPresent()) {
|
||||
return showDocumentNotFound(section, documentPath);
|
||||
}
|
||||
final ContentItem item = itemResult.get();
|
||||
if (!permissionChecker.isPermitted(ItemPrivileges.PUBLISH, item)) {
|
||||
return sectionsUi.showAccessDenied(
|
||||
"sectionIdentifier", sectionIdentifier,
|
||||
"documentPath", documentPath
|
||||
);
|
||||
}
|
||||
|
||||
if (item.getLifecycle() != null) {
|
||||
final Optional<Phase> phaseResult = item
|
||||
.getLifecycle()
|
||||
.getPhases()
|
||||
.stream()
|
||||
.filter(phase -> phase.getPhaseId() == phaseId)
|
||||
.findAny();
|
||||
|
||||
if (!phaseResult.isPresent()) {
|
||||
models.put("section", section.getLabel());
|
||||
models.put("phaseId", phaseId);
|
||||
return "org/librecms/ui/contentsection/phase-not-found.xhtml";
|
||||
}
|
||||
|
||||
final Phase phase = phaseResult.get();
|
||||
final DateTimeFormatter dateTimeFormatter
|
||||
= DateTimeFormatter.ISO_DATE_TIME
|
||||
.withZone(ZoneId.systemDefault());
|
||||
final LocalDateTime startLocalDateTime = LocalDateTime
|
||||
.parse(startDateParam, dateTimeFormatter);
|
||||
phase.setStartDateTime(
|
||||
Date.from(
|
||||
startLocalDateTime.toInstant(
|
||||
ZoneOffset.from(startLocalDateTime)
|
||||
)
|
||||
)
|
||||
);
|
||||
final LocalDateTime endLocalDateTime = LocalDateTime
|
||||
.parse(endDateParam, dateTimeFormatter);
|
||||
phase.setEndDateTime(
|
||||
Date.from(
|
||||
endLocalDateTime.toInstant(
|
||||
ZoneOffset.from(endLocalDateTime)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
phaseRepository.save(phase);
|
||||
}
|
||||
|
||||
return String.format(
|
||||
"redirect:/%s/documents/%s/@publish",
|
||||
sectionIdentifier,
|
||||
documentPath
|
||||
);
|
||||
}
|
||||
|
||||
@POST
|
||||
|
|
@ -453,8 +525,41 @@ public class DocumentController {
|
|||
);
|
||||
}
|
||||
|
||||
public String unpublish() {
|
||||
throw new UnsupportedOperationException("ToDo");
|
||||
@POST
|
||||
@Path("/{documentPath:(.+)?}/@publish")
|
||||
@AuthorizationRequired
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public String unpublish(
|
||||
@PathParam("sectionIdentifider") final String sectionIdentifier,
|
||||
@PathParam("documentPath") final String documentPath
|
||||
) {
|
||||
final Optional<ContentSection> sectionResult = sectionsUi
|
||||
.findContentSection(sectionIdentifier);
|
||||
if (!sectionResult.isPresent()) {
|
||||
return sectionsUi.showContentSectionNotFound(sectionIdentifier);
|
||||
}
|
||||
final ContentSection section = sectionResult.get();
|
||||
|
||||
final Optional<ContentItem> itemResult = itemRepo
|
||||
.findByPath(section, documentPath);
|
||||
if (!itemResult.isPresent()) {
|
||||
return showDocumentNotFound(section, documentPath);
|
||||
}
|
||||
final ContentItem item = itemResult.get();
|
||||
if (!permissionChecker.isPermitted(ItemPrivileges.PUBLISH, item)) {
|
||||
return sectionsUi.showAccessDenied(
|
||||
"sectionIdentifier", sectionIdentifier,
|
||||
"documentPath", documentPath
|
||||
);
|
||||
}
|
||||
|
||||
itemManager.unpublish(item);
|
||||
|
||||
return String.format(
|
||||
"redirect:/%s/documents/%s/@publish",
|
||||
sectionIdentifier,
|
||||
documentPath
|
||||
);
|
||||
}
|
||||
|
||||
@POST
|
||||
|
|
|
|||
Loading…
Reference in New Issue