View Javadoc
1   /*
2    * The coLAB project
3    * Copyright (C) 2022-2023 AlbaSim, MEI, HEIG-VD, HES-SO
4    *
5    * Licensed under the MIT License
6    */
7   package ch.colabproject.colab.api.rest.team;
8   
9   import ch.colabproject.colab.api.controller.team.InstanceMakerManager;
10  import ch.colabproject.colab.api.model.project.InstanceMaker;
11  import ch.colabproject.colab.api.persistence.jpa.project.InstanceMakerDao;
12  import ch.colabproject.colab.generator.model.annotations.AuthenticationRequired;
13  import org.slf4j.Logger;
14  import org.slf4j.LoggerFactory;
15  
16  import javax.inject.Inject;
17  import javax.ws.rs.*;
18  import javax.ws.rs.core.MediaType;
19  import java.util.List;
20  
21  /**
22   * REST InstanceMaker controller
23   *
24   * @author mikkelvestergaard
25   */
26  @Path("instanceMaker")
27  @Consumes(MediaType.APPLICATION_JSON)
28  @Produces(MediaType.APPLICATION_JSON)
29  @AuthenticationRequired
30  public class InstanceMakerRestEndpoint {
31  
32      /**
33       * logger
34       */
35      private static final Logger logger = LoggerFactory.getLogger(InstanceMakerRestEndpoint.class);
36  
37      /**
38       * InstanceMaker specific logic
39       */
40      @Inject
41      private InstanceMakerManager instanceMakerManager;
42  
43      /**
44       * Instance maker persistence handler
45       */
46      @Inject
47      private InstanceMakerDao instanceMakerDao;
48  
49      // *********************************************************************************************
50      // InstanceMakers
51      // *********************************************************************************************
52  
53      /**
54       * Get the instanceMakers of the project
55       *
56       * @param projectId id of the project
57       *
58       * @return list of instanceMakers
59       */
60      @GET
61      @Path("byproject/{projectId: [0-9]+}")
62      public List<InstanceMaker> getInstanceMakersForProject(@PathParam("projectId") Long projectId) {
63          logger.debug("Get project #{} instanceMakers", projectId);
64          return instanceMakerManager.getInstanceMakersForProject(projectId);
65      }
66  
67      /**
68       *  Get an instanceMaker by id
69       *
70       * @param instanceMakerId id of the instanceMaker
71       *
72       * @return the instanceMaker
73       *
74       */
75      @GET
76      @Path("get/{instanceMakerId: [0-9]+}")
77      public InstanceMaker getInstanceMaker(@PathParam("instanceMakerId") Long instanceMakerId) {
78          logger.debug("Get instanceMaker #{}", instanceMakerId);
79          return instanceMakerDao.findInstanceMaker(instanceMakerId);
80      }
81  
82      /**
83       * Delete an instanceMaker by id
84       *
85       * @param instanceMakerId if of the instanceMaker
86       */
87      @DELETE
88      @Path("delete/{instanceMakerId: [0-9]+}")
89      public void deleteInstanceMaker(@PathParam("instanceMakerId") Long instanceMakerId) {
90          logger.debug("Delete instanceMaker #{}", instanceMakerId);
91          instanceMakerManager.deleteInstanceMaker(instanceMakerId);
92      }
93  
94  
95      // *********************************************************************************************
96      // share
97      // *********************************************************************************************
98  
99      /**
100      * Share the model to someone
101      *
102      * @param modelId the id of the model
103      *
104      * @param email the recipient address
105      *
106      * @return the pending potential instance maker
107      */
108     @POST
109     @Path("shareModel/{id: [0-9]+}/{email}")
110     public InstanceMaker shareModel(@PathParam("id") Long modelId, @PathParam("email") String email) {
111         logger.debug("Share model #{} to {}", modelId, email);
112         return instanceMakerManager.shareModel(modelId, email);
113     }
114 }