blob: 416df7748138039ade9c7db8514fbc844db4922c (
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
|
/*******************************************************************************
* 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.core.Response;
import org.eclipse.osee.ats.api.IAtsConfigObject;
import org.eclipse.osee.ats.api.country.CountryEndpointApi;
import org.eclipse.osee.ats.api.country.IAtsCountry;
import org.eclipse.osee.ats.api.country.JaxCountry;
import org.eclipse.osee.ats.api.data.AtsArtifactToken;
import org.eclipse.osee.ats.api.data.AtsArtifactTypes;
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 CountryEndpointImpl extends BaseConfigEndpointImpl<JaxCountry> implements CountryEndpointApi {
public CountryEndpointImpl(IAtsServer atsServer) {
super(AtsArtifactTypes.Country, AtsArtifactToken.CountryFolder, atsServer);
}
@Override
public Response update(JaxCountry country) throws Exception {
ArtifactReadable artifact = atsServer.getArtifact(country.getUuid());
if (artifact == null) {
throw new OseeStateException("Artifact with uuid %d not found", country.getUuid());
}
IAtsChangeSet changes =
atsServer.getStoreService().createAtsChangeSet("Create " + artifactType.getName(), AtsCoreUsers.SYSTEM_USER);
ArtifactReadable configArtifact =
(ArtifactReadable) changes.createArtifact(artifactType, country.getName(), GUID.create(), country.getUuid());
IAtsConfigObject configObject = atsServer.getConfigItemFactory().getConfigObject(configArtifact);
if (!configArtifact.getName().equals(country.getName())) {
changes.setSoleAttributeValue(configObject, CoreAttributeTypes.Name, country.getName());
}
changes.execute();
return Response.created(new URI("/" + country.getUuid())).build();
}
@Override
public JaxCountry getConfigObject(ArtifactId artifact) {
JaxCountry jaxCountry = new JaxCountry();
IAtsCountry country = atsServer.getConfigItemFactory().getCountry(artifact);
jaxCountry.setName(country.getName());
jaxCountry.setUuid(country.getUuid());
jaxCountry.setActive(country.isActive());
jaxCountry.setDescription(country.getDescription());
return jaxCountry;
}
@Override
public List<JaxCountry> getObjects() {
List<JaxCountry> configs = new ArrayList<>();
for (ArtifactReadable art : atsServer.getQuery().andIsOfType(artifactType).getResults()) {
configs.add(getConfigObject(art));
}
return configs;
}
@Override
public ProgramEndpointApi getProgram(long countryUuid) {
return new ProgramEndpointImpl(atsServer, countryUuid);
}
}
|