diff --git a/sci-types-project/src/main/java/org/scientificcms/contenttypes/sciproject/ui/SciProjectAuthoringSteps.java b/sci-types-project/src/main/java/org/scientificcms/contenttypes/sciproject/ui/SciProjectAuthoringSteps.java index 0cf6382..2931de5 100644 --- a/sci-types-project/src/main/java/org/scientificcms/contenttypes/sciproject/ui/SciProjectAuthoringSteps.java +++ b/sci-types-project/src/main/java/org/scientificcms/contenttypes/sciproject/ui/SciProjectAuthoringSteps.java @@ -25,6 +25,7 @@ public class SciProjectAuthoringSteps implements MvcAuthoringSteps { @Override public Set> getResourceClasses() { return Set.of( + SciProjectDescriptionContacts.class, SciProjectDescriptionStepResources.class, SciProjectDescriptionStepService.class, SciProjectFundingStepResources.class, diff --git a/sci-types-project/src/main/java/org/scientificcms/contenttypes/sciproject/ui/SciProjectDescriptionContacts.java b/sci-types-project/src/main/java/org/scientificcms/contenttypes/sciproject/ui/SciProjectDescriptionContacts.java new file mode 100644 index 0000000..5214ca5 --- /dev/null +++ b/sci-types-project/src/main/java/org/scientificcms/contenttypes/sciproject/ui/SciProjectDescriptionContacts.java @@ -0,0 +1,102 @@ +package org.scientificcms.contenttypes.sciproject.ui; + +import org.librecms.contentsection.ContentItem; +import org.librecms.contentsection.ContentItemRepository; +import org.librecms.contentsection.ContentSection; +import org.librecms.ui.contentsections.ContentSectionsUi; +import org.librecms.ui.contentsections.documents.MvcAuthoringSteps; +import org.scientificcms.contenttypes.sciproject.Contact; +import org.scientificcms.contenttypes.sciproject.ContactRepository; +import org.scientificcms.contenttypes.sciproject.SciProject; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.enterprise.context.RequestScoped; +import javax.inject.Inject; +import javax.transaction.Transactional; +import javax.ws.rs.Consumes; +import javax.ws.rs.NotFoundException; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +/** + * + * @author Jens Pelzetter + */ +@RequestScoped +@Path(MvcAuthoringSteps.PATH_PREFIX + "sciproject-description/contacts") +public class SciProjectDescriptionContacts { + + @Inject + private ContactRepository contactRepo; + + @Inject + private ContentItemRepository itemRepo; + + @Inject + private ContentSectionsUi sectionsUi; + + @POST + @Path("/save-order") + @Consumes(MediaType.APPLICATION_JSON) + @Transactional(Transactional.TxType.REQUIRED) + public Response saveOrder( + @PathParam(MvcAuthoringSteps.SECTION_IDENTIFIER_PATH_PARAM) + final String sectionIdentifier, + @PathParam(MvcAuthoringSteps.DOCUMENT_PATH_PATH_PARAM_NAME) + final String documentPath, + final List order + ) { + final ContentSection contentSection = sectionsUi + .findContentSection(sectionIdentifier) + .orElseThrow( + () -> new NotFoundException( + String.format( + "No content identifed by %s found.", + sectionIdentifier + ) + ) + ); + + final ContentItem document = itemRepo + .findByPath(contentSection, documentPath) + .orElseThrow( + () -> new NotFoundException( + String.format( + "No document for path %s in section %s.", + documentPath, + contentSection.getLabel() + ) + ) + ); + + if (!(document instanceof SciProject)) { + throw new NotFoundException( + String.format( + "No SciProject for path %s in section %s.", + documentPath, + contentSection.getLabel() + ) + ); + } + + final Map orderMap = new HashMap<>(); + for (int i = 0; i < order.size(); i++) { + orderMap.put(Long.parseLong(order.get(i)), (long) i); + } + + final SciProject project = (SciProject) document; + for (final Contact contact : project.getContacts()) { + contact.setOrder(orderMap.get(contact.getContactId())); + contactRepo.save(contact); + } + + return Response.ok().build(); + } + +} diff --git a/scicms-bundle-devel-wildfly/runtime.properties b/scicms-bundle-devel-wildfly/runtime.properties index 6bfc3af..a702584 100644 --- a/scicms-bundle-devel-wildfly/runtime.properties +++ b/scicms-bundle-devel-wildfly/runtime.properties @@ -2,6 +2,6 @@ libreccm.debug.suspend=n libreccm.database.host=localhost libreccm.database.port=5432 -libreccm.database.name=ccm-devel +libreccm.database.name=scicms-devel libreccm.database.user=ccm libreccm.database.password=ccm47web