Sorting of contacts working
parent
2943c5be22
commit
cbfdf563f1
|
|
@ -25,6 +25,7 @@ public class SciProjectAuthoringSteps implements MvcAuthoringSteps {
|
|||
@Override
|
||||
public Set<Class<?>> getResourceClasses() {
|
||||
return Set.of(
|
||||
SciProjectDescriptionContacts.class,
|
||||
SciProjectDescriptionStepResources.class,
|
||||
SciProjectDescriptionStepService.class,
|
||||
SciProjectFundingStepResources.class,
|
||||
|
|
|
|||
|
|
@ -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 <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@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<String> 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<Long, Long> 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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue