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
|
/*******************************************************************************
* 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.InsertionEndpointApi;
import org.eclipse.osee.ats.api.program.IAtsProgram;
import org.eclipse.osee.ats.api.program.JaxProgram;
import org.eclipse.osee.ats.api.program.ProgramEndpointApi;
import org.eclipse.osee.ats.api.util.IAtsChangeSet;
import org.eclipse.osee.ats.core.users.AtsCoreUsers;
import org.eclipse.osee.ats.impl.IAtsServer;
import org.eclipse.osee.ats.impl.config.BaseConfigEndpointImpl;
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 ProgramEndpointImpl extends BaseConfigEndpointImpl<JaxProgram> implements ProgramEndpointApi {
private final long countryUuid;
public ProgramEndpointImpl(IAtsServer atsServer) {
this(atsServer, 0L);
}
public ProgramEndpointImpl(IAtsServer atsServer, long countryUuid) {
super(AtsArtifactTypes.Program, null, atsServer);
this.countryUuid = countryUuid;
}
@PUT
@Override
public Response update(JaxProgram program) throws Exception {
ArtifactReadable artifact = atsServer.getArtifact(program.getUuid());
if (artifact == null) {
throw new OseeStateException("Artifact with uuid %d not found", program.getUuid());
}
IAtsChangeSet changes =
atsServer.getStoreService().createAtsChangeSet("Create " + artifactType.getName(), AtsCoreUsers.SYSTEM_USER);
ArtifactReadable configArtifact =
(ArtifactReadable) changes.createArtifact(artifactType, program.getName(), GUID.create(), program.getUuid());
IAtsConfigObject configObject = atsServer.getConfigItemFactory().getConfigObject(configArtifact);
if (!configArtifact.getName().equals(program.getName())) {
changes.setSoleAttributeValue(configObject, CoreAttributeTypes.Name, program.getName());
}
changes.execute();
return Response.created(new URI("/" + program.getUuid())).build();
}
@Override
public JaxProgram getConfigObject(ArtifactId artifact) {
JaxProgram jaxProgram = new JaxProgram();
IAtsProgram program = atsServer.getConfigItemFactory().getProgram(artifact);
jaxProgram.setName(program.getName());
jaxProgram.setUuid(program.getUuid());
jaxProgram.setActive(program.isActive());
jaxProgram.setDescription(program.getDescription());
return jaxProgram;
}
@Override
public List<JaxProgram> getObjects() {
List<JaxProgram> configs = new ArrayList<>();
if (countryUuid == 0L) {
for (ArtifactReadable art : atsServer.getQuery().andIsOfType(artifactType).getResults()) {
configs.add(getConfigObject(art));
}
} else {
for (ArtifactReadable art : atsServer.getArtifact(countryUuid).getRelated(
AtsRelationTypes.CountryToProgram_Program)) {
JaxProgram program = getConfigObject(art);
program.setCountryUuid(countryUuid);
configs.add(program);
}
}
return configs;
}
@Override
protected void create(JaxProgram jaxProgram, ArtifactId programArtId, IAtsChangeSet changes) {
ArtifactReadable programArt = (ArtifactReadable) programArtId;
if (programArt.getRelatedCount(AtsRelationTypes.CountryToProgram_Country) == 0) {
ArtifactReadable countryArt = atsServer.getArtifact(jaxProgram.getCountryUuid());
changes.relate(countryArt, AtsRelationTypes.CountryToProgram_Program, programArt);
}
}
@Override
public InsertionEndpointApi getInsertion(long programUuid) {
return new InsertionEndpointImpl(atsServer, programUuid);
}
}
|