use of org.eclipse.winery.common.version.WineryVersion in project winery by eclipse.
the class AbstractComponentInstanceResource method getElementAsJson.
@GET
@Produces(MediaType.APPLICATION_JSON)
public Object getElementAsJson(@QueryParam("versions") @ApiParam("If set, a list of available versions is returned.") String versions, @QueryParam("subComponents") String subComponents, @QueryParam("compareTo") String compareTo, @QueryParam("asChangeLog") String asChangeLog) {
if (!requestRepository.exists(this.id)) {
throw new NotFoundException();
}
try {
if (Objects.nonNull(versions)) {
return WineryVersionUtils.getAllVersionsOfOneDefinition(this.id, requestRepository);
} else if (Objects.nonNull(subComponents)) {
return requestRepository.getReferencedDefinitionsChildIds(this.id).stream().map(item -> new QNameWithTypeApiData(item.getXmlId().getDecoded(), item.getNamespace().getDecoded(), item.getGroup())).collect(Collectors.toList());
} else if (Objects.nonNull(compareTo)) {
WineryVersion version = VersionUtils.getVersion(compareTo);
ToscaDiff compare = BackendUtils.compare(this.id, version, requestRepository);
if (Objects.nonNull(asChangeLog)) {
return compare.getChangeLog();
} else {
return compare;
}
} else {
return BackendUtils.getDefinitionsHavingCorrectImports(requestRepository, this.id);
}
} catch (Exception e) {
LOGGER.warn("Failed to return element at {} as JSON due to exception.", this.id, e);
throw new WebApplicationException(e);
}
}
use of org.eclipse.winery.common.version.WineryVersion in project winery by eclipse.
the class BackendUtilsTestWithGitBackedRepository method getVersionListOfAnOldComponentVersionWhichIsReleasable.
@Test
public void getVersionListOfAnOldComponentVersionWhichIsReleasable() throws Exception {
this.setRevisionTo("origin/plain");
NodeTypeId id = new NodeTypeId("http://opentosca.org/nodetypes", "NodeTypeWithALowerReleasableManagementVersion_2-w2-wip1", false);
List<WineryVersion> versionList = WineryVersionUtils.getAllVersionsOfOneDefinition(id, repository);
WineryVersion version = versionList.get(versionList.size() - 2);
assertFalse(version.isEditable());
assertTrue(version.isReleasable());
}
use of org.eclipse.winery.common.version.WineryVersion in project winery by eclipse.
the class BackendUtilsTestWithGitBackedRepository method getVersionWithEditableFlag.
@Test
public void getVersionWithEditableFlag() throws Exception {
this.setRevisionTo("origin/plain");
NodeTypeId id = new NodeTypeId("http://opentosca.org/nodetypes", "NodeTypeWith5Versions_0.3.4-w3", false);
// Make some changes to the file
makeSomeChanges(id);
List<WineryVersion> versions = WineryVersionUtils.getAllVersionsOfOneDefinition(id, repository);
assertTrue(versions.get(0).isEditable());
List<WineryVersion> collect = versions.stream().filter(item -> !item.isEditable()).collect(Collectors.toList());
assertEquals(4, collect.size());
}
use of org.eclipse.winery.common.version.WineryVersion in project winery by eclipse.
the class BackendUtilsTestWithGitBackedRepository method getVersionWithEditableFlagAndChangesInAFileWhichIsNotTheToscaFile.
@Test
public void getVersionWithEditableFlagAndChangesInAFileWhichIsNotTheToscaFile() throws Exception {
this.setRevisionTo("origin/plain");
NodeTypeId id = new NodeTypeId("http://opentosca.org/nodetypes", "NodeTypeWith5Versions_0.3.4-w3", false);
// Make some changes to an associated file
RepositoryFileReference ref = new RepositoryFileReference(id, EncodingUtil.URLdecode("README.md"));
RepositoryFactory.getRepository().putContentToFile(ref, "someUnguessableContent", MediaType.TEXT_PLAIN);
List<WineryVersion> versions = WineryVersionUtils.getAllVersionsOfOneDefinition(id, repository);
assertTrue(versions.get(0).isEditable());
List<WineryVersion> collect = versions.stream().filter(item -> !item.isEditable()).collect(Collectors.toList());
assertEquals(4, collect.size());
}
use of org.eclipse.winery.common.version.WineryVersion in project winery by eclipse.
the class BackendUtilsTestWithGitBackedRepository method getVersionsOfOneDefinitionWithComponentThatDoesNotHaveAVersion.
@Test
public void getVersionsOfOneDefinitionWithComponentThatDoesNotHaveAVersion() throws Exception {
this.setRevisionTo("origin/plain");
DefinitionsChildId id = new RelationshipTypeId("http://plain.winery.opentosca.org/relationshiptypes", "RelationshipTypeWithoutProperties", false);
List<WineryVersion> versions = WineryVersionUtils.getAllVersionsOfOneDefinition(id, repository);
assertEquals(1, versions.size());
assertEquals("", versions.get(0).toString());
}
Aggregations