use of org.eclipse.winery.common.version.WineryVersion in project winery by eclipse.
the class ServiceTemplateResource method createNewPlaceholderVersion.
@POST()
@Path("createplaceholderversion")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response createNewPlaceholderVersion() throws IOException {
LOGGER.debug("Creating new placeholder version of Service Template {}...", this.getId());
ServiceTemplateId id = (ServiceTemplateId) this.getId();
WineryVersion version = VersionUtils.getVersion(id.getXmlId().getDecoded());
WineryVersion newVersion = new WineryVersion("gdm-" + version.toString(), 1, 1);
IRepository repository = RepositoryFactory.getRepository();
ServiceTemplateId newId = new ServiceTemplateId(id.getNamespace().getDecoded(), VersionUtils.getNameWithoutVersion(id.getXmlId().getDecoded()) + WineryVersion.WINERY_NAME_FROM_VERSION_SEPARATOR + newVersion.toString(), false);
if (repository.exists(newId)) {
repository.forceDelete(newId);
}
ResourceResult response = RestUtils.duplicate(id, newId);
if (response.getStatus() == Status.CREATED) {
response.setUri(null);
response.setMessage(new QNameApiData(newId));
}
LOGGER.debug("Created Service Template {}", newId.getQName());
return response.getResponse();
}
use of org.eclipse.winery.common.version.WineryVersion in project winery by eclipse.
the class ServiceTemplateResource method createLiveModelingVersion.
@POST()
@Path("createlivemodelingversion")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response createLiveModelingVersion() {
LOGGER.debug("Creating live modeling version of Service Template {}...", this.getId().getQName());
ServiceTemplateId id = (ServiceTemplateId) this.getId();
WineryVersion version = VersionUtils.getVersion(id.getQName().toString());
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd-HHmmss");
WineryVersion newVersion = new WineryVersion(version.toString() + "-live-" + dateFormat.format(new Date()), 1, 0);
String newComponentVersionId = VersionSupport.getNewComponentVersionId(id, "live-" + dateFormat.format(new Date()));
ServiceTemplateId newId = new ServiceTemplateId(id.getNamespace().getDecoded(), newComponentVersionId, false);
ResourceResult response = RestUtils.duplicate(id, newId);
if (response.getStatus() == Status.CREATED) {
response.setUri(null);
response.setMessage(new QNameApiData(newId));
}
LOGGER.debug("Created Service Template {}", newId.getQName());
return response.getResponse();
}
use of org.eclipse.winery.common.version.WineryVersion in project winery by eclipse.
the class ServiceTemplateResource method createParticipantsVersion.
@POST()
@Path("createparticipantsversion")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public List<Response> createParticipantsVersion() throws IOException {
IRepository repo = RepositoryFactory.getRepository();
// create list of responses because we create multiple resources at once
List<Response> listOfResponses = new ArrayList<>();
LOGGER.debug("Creating new participants version of Service Template {}...", this.getId());
ServiceTemplateId id = (ServiceTemplateId) this.getId();
WineryVersion version = VersionUtils.getVersion(id.getXmlId().getDecoded());
TTopologyTemplate topologyTemplate = this.getTopology();
List<TTag> tags = new ArrayList<>();
Splitting splitting = new Splitting();
if (topologyTemplate.getParticipants() != null) {
for (OTParticipant participant : topologyTemplate.getParticipants()) {
// check if tag with partner in service template
WineryVersion newVersion = new WineryVersion(participant.getName() + "-" + version.toString().replace("gdm", "ldm"), 1, 1);
List<OTParticipant> newParticipantList = new ArrayList<>(topologyTemplate.getParticipants());
// new tag to define participant of service template
tags.add(new TTag.Builder("participant", participant.getName()).build());
String choreoValue = splitting.calculateChoreographyTag(this.getServiceTemplate().getTopologyTemplate().getNodeTemplates(), participant.getName());
tags.add(new TTag.Builder("choreography", choreoValue).build());
ServiceTemplateId newId = new ServiceTemplateId(id.getNamespace().getDecoded(), VersionUtils.getNameWithoutVersion(id.getXmlId().getDecoded()) + WineryVersion.WINERY_NAME_FROM_VERSION_SEPARATOR + newVersion.toString(), false);
if (repo.exists(newId)) {
repo.forceDelete(newId);
}
ResourceResult response = RestUtils.duplicate(id, newId);
if (response.getStatus() == Status.CREATED) {
response.setUri(null);
response.setMessage(new QNameApiData(newId));
}
TServiceTemplate tempServiceTempl = repo.getElement(newId);
tempServiceTempl.setTags(tags);
tempServiceTempl.getTopologyTemplate().setParticipants(newParticipantList);
listOfResponses.add(response.getResponse());
// set element to propagate changed tags
repo.setElement(newId, tempServiceTempl);
}
}
return listOfResponses;
}
use of org.eclipse.winery.common.version.WineryVersion in project winery by eclipse.
the class TopologyTemplateResource method getNewVersionList.
@GET
@Path("newversions")
@Produces(MediaType.APPLICATION_JSON)
public List<NewVersionListElement> getNewVersionList() {
IRepository repository = RepositoryFactory.getRepository();
Map<QName, TNodeType> nodeTypes = repository.getQNameToElementMapping(NodeTypeId.class);
Map<QName, List<WineryVersion>> versionElements = new HashMap<>();
for (TNodeTemplate node : this.topologyTemplate.getNodeTemplates()) {
if (nodeTypes.containsKey(node.getType())) {
NodeTypeId nodeTypeId = new NodeTypeId(node.getType());
if (!versionElements.containsKey(nodeTypeId.getQName())) {
List<WineryVersion> versionList = WineryVersionUtils.getAllVersionsOfOneDefinition(nodeTypeId, repository).stream().filter(wineryVersion -> {
QName qName = VersionSupport.getDefinitionInTheGivenVersion(nodeTypeId, wineryVersion).getQName();
NamespaceProperties namespaceProperties = repository.getNamespaceManager().getNamespaceProperties(qName.getNamespaceURI());
return !(namespaceProperties.isGeneratedNamespace() || ModelUtilities.isFeatureType(qName, nodeTypes));
}).collect(Collectors.toList());
versionElements.put(nodeTypeId.getQName(), versionList);
}
}
}
return versionElements.entrySet().stream().map(qNameListEntry -> new NewVersionListElement(qNameListEntry.getKey(), qNameListEntry.getValue())).collect(Collectors.toList());
}
use of org.eclipse.winery.common.version.WineryVersion in project winery by eclipse.
the class RestUtilsWithGitBackendTest method releaseComponentWhichHasNotBeenCommitted.
@Test
public void releaseComponentWhichHasNotBeenCommitted() throws Exception {
this.setRevisionTo("origin/plain");
NodeTypeId id = new NodeTypeId("http://opentosca.org/nodetypes", "NodeTypeWithALowerReleasableManagementVersion_2-w2-wip1", false);
NodeTypeId releasedId = new NodeTypeId("http://opentosca.org/nodetypes", "NodeTypeWithALowerReleasableManagementVersion_2-w2", false);
int formerVersionCount = WineryVersionUtils.getAllVersionsOfOneDefinition(id, repository).size();
// simulate a non-committed component
makeSomeChanges(id);
Response response = RestUtils.releaseVersion(id);
int finalVersionCount = WineryVersionUtils.getAllVersionsOfOneDefinition(releasedId, repository).size();
WineryVersion version = WineryVersionUtils.getCurrentVersionWithAllFlags(releasedId, repository);
assertEquals(201, response.getStatus());
assertEquals(formerVersionCount + 1, finalVersionCount);
assertFalse(version.isReleasable());
assertEquals(0, version.getWorkInProgressVersion());
}
Aggregations