Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new API to deal with the observingModes being attached to the Submitt… #53

Merged
merged 4 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions src/main/java/org/orph2020/pst/AppLifecycleBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
import org.apache.commons.io.FileUtils;
import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.ivoa.dm.proposal.management.ProposalCycle;
import org.ivoa.dm.proposal.prop.EmerlinExample;
import org.ivoa.dm.proposal.prop.ExampleProposal;
import org.ivoa.dm.proposal.prop.ObservingProposal;
import org.ivoa.dm.proposal.prop.Person;
import org.ivoa.dm.proposal.prop.*;
import org.jboss.logging.Logger;
import org.orph2020.pst.apiimpl.entities.SubjectMap;

Expand All @@ -26,6 +23,13 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

@ApplicationScoped
public class AppLifecycleBean {
Expand All @@ -46,16 +50,21 @@ void onStart(@Observes StartupEvent ev) {
Long i = em.createQuery("select count(o) from Observatory o", Long.class).getSingleResult();
if(i.intValue() == 0) {

EmerlinExample ex = new EmerlinExample();
ProposalCycle cy = ex.getCycle();
cy.persistRefs(em);
em.persist(cy);
ObservingProposal pr = new ExampleProposal().getProposal();
pr.persistRefs(em);
em.persist(pr);
// add the example proposals.
FullExample fullExample = new FullExample();
List<ProposalCycle> cycles = fullExample.getManagementModel().getContent(ProposalCycle.class);
LocalDate now = LocalDate.now();
for (ProposalCycle cycle : cycles) {
cycle.setSubmissionDeadline(new Date(now.plusWeeks(2).atStartOfDay().atOffset(ZoneOffset.UTC).toEpochSecond()*1000));
cycle.setObservationSessionStart(new Date(now.plusMonths(2).atStartOfDay().atOffset(ZoneOffset.UTC).toEpochSecond()*1000));
cycle.setObservationSessionEnd(new Date(now.plusMonths(6).atStartOfDay().atOffset(ZoneOffset.UTC).toEpochSecond()*1000));
}
fullExample.saveTodB(em);

ObservingProposal pr = fullExample.getProposalModel().getContent(ObservingProposal.class).get(0);
//here we create document store directories that would be normally created
// in the implementation of API call "createProposal"
// FIXME not sure if justifications are copied too...
try {
Files.createDirectories(Paths.get(
documentStoreRoot,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.orph2020.pst.apiimpl.entities;
/*
* Created on 22/10/2024 by Paul Harrison (paul.harrison@manchester.ac.uk).
*/

import org.eclipse.microprofile.openapi.annotations.media.Schema;
import org.ivoa.dm.proposal.management.ObservationConfiguration;

import java.util.List;

/**
* Specify the submission parameters in the API.
*/
@Schema(
description = "The submission configuration in terms of IDs "
)
public class SubmissionConfiguration {
public long proposalId;
public List<ObservationConfigMapping> config;



public SubmissionConfiguration(long proposalId, List<ObservationConfigMapping> config) {

this.proposalId = proposalId;
this.config = config;
}

@Schema(
description = "the mapping between a list of observationIDs and ObservationMode id "
)
public static class ObservationConfigMapping {
public List<Long> observationIds;
public long modeId;

public ObservationConfigMapping(List<Long> observationIds, long modeId) {
this.observationIds = observationIds;
this.modeId = modeId;
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,15 @@ private ObservingMode findObservingModeByQuery(long cycleId, long modeId) {
}

@GET
@Operation(summary = "get all the ObservingMode identifiers associated with the given ProposalCycle")
public List<ObjectIdentifier> getCycleObservingModes(@PathParam("cycleId") Long cycleId)
@Operation(summary = "get all the ObservingModes associated with the given ProposalCycle")
public List<ObservingMode> getCycleObservingModes(@PathParam("cycleId") Long cycleId)
{
return getObjectIdentifiers("Select o._id,o.name from ProposalCycle p inner join p.observingModes o where p._id = "+cycleId+" order by o.name");
TypedQuery<ObservingMode> q = em.createQuery(
"select om from ProposalCycle c join c.observingModes om where c._id = :cid",
ObservingMode.class
);
q.setParameter("cid", cycleId);
return q.getResultList();
}

@GET
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import jakarta.ws.rs.*;
import jakarta.ws.rs.core.MediaType;

import java.util.*;

@Path("proposalCycles")
Expand All @@ -35,7 +36,7 @@ public List<ObjectIdentifier> getProposalCycles(@RestQuery boolean includeClosed
if(includeClosed)
return super.getObjectIdentifiers("SELECT o._id,o.title FROM ProposalCycle o ORDER BY o.title");
else
return super.getObjectIdentifiers("SELECT o._id,o.title FROM ProposalCycle o ORDER BY o.title");//FIXME actually do only return open
return super.getObjectIdentifiers("SELECT o._id,o.title FROM ProposalCycle o WHERE o.submissionDeadline > CURRENT_TIMESTAMP() ORDER BY o.title");
}


Expand Down Expand Up @@ -96,7 +97,8 @@ public ProposalCycleDates getProposalCycleDates(@PathParam("cycleCode") Long cyc
ProposalCycle fullCycle = findObject(ProposalCycle.class, cycleCode);

return new ProposalCycleDates(fullCycle.getTitle(), fullCycle.getSubmissionDeadline(),
fullCycle.getObservationSessionStart(), fullCycle.getObservationSessionEnd());
fullCycle.getObservationSessionStart(), fullCycle.getObservationSessionEnd(),
fullCycle.getObservatory());
}

@PUT
Expand All @@ -115,7 +117,8 @@ public ProposalCycleDates replaceCycleDeadline(
cycle.setSubmissionDeadline(replacementDeadline);

return new ProposalCycleDates(cycle.getTitle(), cycle.getSubmissionDeadline(),
cycle.getObservationSessionStart(), cycle.getObservationSessionEnd());
cycle.getObservationSessionStart(), cycle.getObservationSessionEnd(),
cycle.getObservatory());
}


Expand All @@ -135,7 +138,8 @@ public ProposalCycleDates replaceCycleSessionStart(
cycle.setObservationSessionStart(replacementStart);

return new ProposalCycleDates(cycle.getTitle(), cycle.getSubmissionDeadline(),
cycle.getObservationSessionStart(), cycle.getObservationSessionEnd());
cycle.getObservationSessionStart(), cycle.getObservationSessionEnd(),
cycle.getObservatory());
}

@PUT
Expand All @@ -154,7 +158,8 @@ public ProposalCycleDates replaceCycleSessionEnd(
cycle.setObservationSessionEnd(replacementEnd);

return new ProposalCycleDates(cycle.getTitle(), cycle.getSubmissionDeadline(),
cycle.getObservationSessionStart(), cycle.getObservationSessionEnd());
cycle.getObservationSessionStart(), cycle.getObservationSessionEnd(),
cycle.getObservatory());
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
package org.orph2020.pst.apiimpl.rest;


import jakarta.persistence.TypedQuery;
import jakarta.transaction.Transactional;
import jakarta.ws.rs.*;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import org.eclipse.microprofile.openapi.annotations.Operation;
import org.eclipse.microprofile.openapi.annotations.tags.Tag;
import org.ivoa.dm.proposal.management.*;
import org.ivoa.dm.proposal.prop.Observation;
import org.ivoa.dm.proposal.prop.ObservingProposal;
import org.orph2020.pst.apiimpl.entities.SubmissionConfiguration;
import org.orph2020.pst.common.json.ObjectIdentifier;
import org.orph2020.pst.common.json.ProposalSynopsis;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

Expand All @@ -24,13 +28,13 @@ public class SubmittedProposalResource extends ObjectResourceBase{
@Operation(summary = "get the identifiers for the SubmittedProposals in the ProposalCycle")
public List<ObjectIdentifier> getSubmittedProposals(@PathParam("cycleCode") Long cycleCode)
{
String select = "select s._id,p.title ";
String select = "select s._id,s.proposal.title ";
String from = "from ProposalCycle c ";
String innerJoins = "inner join c.submittedProposals s inner join s.proposal p ";
String where = "where c._id=" + cycleCode + " ";
String orderBy = "order by p.title";

return getObjectIdentifiers(select + from + innerJoins + where + orderBy);
return getObjectIdentifiers("select s._id, s.proposal.title from ProposalCycle c inner join c.submittedProposals s where c._id=" + cycleCode + " order by s.proposal.title ");
}

@GET
Expand Down Expand Up @@ -63,36 +67,46 @@ public List<ObjectIdentifier> getSubmittedNotYetAllocated(@PathParam("cycleCode"
}


@PUT
@POST
@Operation(summary = "submit a proposal")
@Consumes(MediaType.TEXT_PLAIN)
@Consumes(MediaType.APPLICATION_JSON)
@Transactional(rollbackOn = {WebApplicationException.class})
public ProposalSynopsis submitProposal(@PathParam("cycleCode") long cycleId, long proposalId)
public ProposalSynopsis submitProposal(@PathParam("cycleCode") long cycleId, SubmissionConfiguration submissionConfiguration)
{
//FIXME -this needs to do new submission process

/*
SubmittedProposals need to remember the original proposalId from which they create
TODO SubmittedProposals need to remember the original proposalId from which they create
a clone; it is the clone to which the SubmittedProposal refers, NOT the original
proposal. SubmittedProposals currently do not have a means to do this.

In this way, we can check for proposals that have been re-submitted i.e., compare the
'proposalId' input to the same in the list of SubmittedProposals, and remove any now stale
SubmittedProposals and their clones, before adding a new SubmittedProposal with a new,
updated clone.
It is debatable whether this should be in the model or just a separate table that POLARIS itself maintains
*/

final long proposalId = submissionConfiguration.proposalId;
ProposalCycle cycle = findObject(ProposalCycle.class,cycleId);

ObservingProposal proposal = findObject(ObservingProposal.class, proposalId);

List<ObservationConfiguration> configMappings = new ArrayList<>();
for (SubmissionConfiguration.ObservationConfigMapping cm: submissionConfiguration.config)
{
ObservingMode mode = findObject(ObservingMode.class, cm.modeId);
TypedQuery<Observation> obsquery = em.createQuery("select o from Observation o where o._id in :ids ", Observation.class);
obsquery.setParameter("ids", cm.observationIds);
List<Observation> observations = obsquery.getResultList();
configMappings.add(new ObservationConfiguration(observations,mode));

}

new ProposalManagementModel().createContext(); // TODO API subject to change
ObservingProposal pclone = new ObservingProposal(proposal); // create clone TODO perhaps we should not create the clone
pclone.updateClonedReferences();// TODO API subject to change
pclone.setSubmitted(true);
em.persist(pclone);
//constructor args.:(submission date, config, successful, reviews-complete-date, reviews, the-proposal)
//FIXME need to gather the config
SubmittedProposal submittedProposal = new SubmittedProposal(pclone, null, new Date(), false, new Date(0L), null );

SubmittedProposal submittedProposal = new SubmittedProposal(pclone, configMappings, new Date(), false, new Date(0L), null );
cycle.addToSubmittedProposals(submittedProposal);
em.merge(cycle);

Expand Down
Loading
Loading