Skip to main content
summaryrefslogtreecommitdiffstats
blob: 5011f424d3901ba4c50b58d87930dafbd2dc684f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*******************************************************************************
 * Copyright (c) 2014 Boeing.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Boeing - initial API and implementation
 *******************************************************************************/
package org.eclipse.osee.ats.rest.internal.config;

import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import javax.ws.rs.PUT;
import javax.ws.rs.core.Response;
import org.eclipse.osee.ats.api.IAtsConfigObject;
import org.eclipse.osee.ats.api.data.AtsArtifactTypes;
import org.eclipse.osee.ats.api.data.AtsRelationTypes;
import org.eclipse.osee.ats.api.insertion.IAtsInsertion;
import org.eclipse.osee.ats.api.insertion.InsertionActivityEndpointApi;
import org.eclipse.osee.ats.api.insertion.InsertionEndpointApi;
import org.eclipse.osee.ats.api.insertion.JaxInsertion;
import org.eclipse.osee.ats.api.util.IAtsChangeSet;
import org.eclipse.osee.ats.core.users.AtsCoreUsers;
import org.eclipse.osee.ats.rest.IAtsServer;
import org.eclipse.osee.framework.core.data.ArtifactId;
import org.eclipse.osee.framework.core.enums.CoreAttributeTypes;
import org.eclipse.osee.framework.jdk.core.type.OseeStateException;
import org.eclipse.osee.framework.jdk.core.util.GUID;
import org.eclipse.osee.orcs.data.ArtifactReadable;

/**
 * Donald G. Dunne
 */
public class InsertionEndpointImpl extends BaseConfigEndpointImpl<JaxInsertion> implements InsertionEndpointApi {

   private final long programUuid;

   public InsertionEndpointImpl(IAtsServer atsServer) {
      this(atsServer, 0L);
   }

   public InsertionEndpointImpl(IAtsServer atsServer, long programUuid) {
      super(AtsArtifactTypes.Insertion, null, atsServer);
      this.programUuid = programUuid;
   }

   @PUT
   @Override
   public Response update(JaxInsertion insertion) throws Exception {
      ArtifactReadable artifact = atsServer.getArtifact(insertion.getUuid());
      if (artifact == null) {
         throw new OseeStateException("Artifact with uuid %d not found", insertion.getUuid());
      }
      IAtsChangeSet changes =
         atsServer.getStoreService().createAtsChangeSet("Create " + artifactType.getName(), AtsCoreUsers.SYSTEM_USER);
      ArtifactReadable configArtifact =
         (ArtifactReadable) changes.createArtifact(artifactType, insertion.getName(), GUID.create(),
            insertion.getUuid());
      IAtsConfigObject configObject = atsServer.getConfigItemFactory().getConfigObject(configArtifact);
      if (!configArtifact.getName().equals(insertion.getName())) {
         changes.setSoleAttributeValue(configObject, CoreAttributeTypes.Name, insertion.getName());
      }
      changes.execute();
      return Response.created(new URI("/" + insertion.getUuid())).build();
   }

   @Override
   public JaxInsertion getConfigObject(ArtifactId artifact) {
      JaxInsertion jaxInsertion = new JaxInsertion();
      IAtsInsertion insertion = atsServer.getConfigItemFactory().getInsertion(artifact);
      jaxInsertion.setName(insertion.getName());
      jaxInsertion.setUuid(insertion.getUuid());
      jaxInsertion.setActive(insertion.isActive());
      jaxInsertion.setDescription(insertion.getDescription());
      return jaxInsertion;
   }

   @Override
   public List<JaxInsertion> getObjects() {
      List<JaxInsertion> insertions = new ArrayList<>();
      if (programUuid == 0L) {
         for (ArtifactReadable art : atsServer.getQuery().andIsOfType(artifactType).getResults()) {
            insertions.add(getConfigObject(art));
         }
      } else {
         for (ArtifactReadable insertionArt : atsServer.getArtifact(programUuid).getRelated(
            AtsRelationTypes.ProgramToInsertion_Insertion)) {
            JaxInsertion insertion = getConfigObject(insertionArt);
            insertion.setProgramUuid(programUuid);
            insertions.add(insertion);
         }
      }
      return insertions;
   }

   @Override
   protected void create(JaxInsertion jaxInsertion, ArtifactId insertionArtId, IAtsChangeSet changes) {
      ArtifactReadable insertionArt = (ArtifactReadable) insertionArtId;
      if (insertionArt.getRelatedCount(AtsRelationTypes.ProgramToInsertion_Program) == 0) {
         ArtifactReadable programArt = atsServer.getArtifact(jaxInsertion.getProgramUuid());
         changes.relate(programArt, AtsRelationTypes.ProgramToInsertion_Insertion, insertionArt);
      }
   }

   @Override
   public InsertionActivityEndpointApi getInsertionActivity(long insertionUuid) {
      return new InsertionActivityEndpointImpl(atsServer, insertionUuid);
   }

}

Back to the top