Search in sources :

Example 31 with WineryVersion

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);
    }
}
Also used : ToscaDiff(org.eclipse.winery.model.version.ToscaDiff) QNameWithTypeApiData(org.eclipse.winery.repository.rest.resources.apiData.QNameWithTypeApiData) WebApplicationException(javax.ws.rs.WebApplicationException) NotFoundException(javax.ws.rs.NotFoundException) JAXBException(javax.xml.bind.JAXBException) NotFoundException(javax.ws.rs.NotFoundException) SAXException(org.xml.sax.SAXException) WebApplicationException(javax.ws.rs.WebApplicationException) IOException(java.io.IOException) WineryVersion(org.eclipse.winery.common.version.WineryVersion) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 32 with WineryVersion

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());
}
Also used : NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) WineryVersion(org.eclipse.winery.common.version.WineryVersion) Test(org.junit.jupiter.api.Test)

Example 33 with WineryVersion

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());
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) TDefinitions(org.eclipse.winery.model.tosca.TDefinitions) RepositoryFileReference(org.eclipse.winery.repository.common.RepositoryFileReference) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) MediaType(org.apache.tika.mime.MediaType) Collectors(java.util.stream.Collectors) RelationshipTypeId(org.eclipse.winery.model.ids.definitions.RelationshipTypeId) LinkedHashMap(java.util.LinkedHashMap) EncodingUtil(org.eclipse.winery.model.ids.EncodingUtil) Test(org.junit.jupiter.api.Test) WineryVersion(org.eclipse.winery.common.version.WineryVersion) List(java.util.List) VersionState(org.eclipse.winery.common.version.VersionState) TestWithGitBackedRepository(org.eclipse.winery.repository.TestWithGitBackedRepository) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ToscaDiff(org.eclipse.winery.model.version.ToscaDiff) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) ModelUtilities(org.eclipse.winery.model.tosca.utils.ModelUtilities) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) QName(javax.xml.namespace.QName) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) PolicyTemplateId(org.eclipse.winery.model.ids.definitions.PolicyTemplateId) TPolicyTemplate(org.eclipse.winery.model.tosca.TPolicyTemplate) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) WineryVersion(org.eclipse.winery.common.version.WineryVersion) Test(org.junit.jupiter.api.Test)

Example 34 with WineryVersion

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());
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) TDefinitions(org.eclipse.winery.model.tosca.TDefinitions) RepositoryFileReference(org.eclipse.winery.repository.common.RepositoryFileReference) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) MediaType(org.apache.tika.mime.MediaType) Collectors(java.util.stream.Collectors) RelationshipTypeId(org.eclipse.winery.model.ids.definitions.RelationshipTypeId) LinkedHashMap(java.util.LinkedHashMap) EncodingUtil(org.eclipse.winery.model.ids.EncodingUtil) Test(org.junit.jupiter.api.Test) WineryVersion(org.eclipse.winery.common.version.WineryVersion) List(java.util.List) VersionState(org.eclipse.winery.common.version.VersionState) TestWithGitBackedRepository(org.eclipse.winery.repository.TestWithGitBackedRepository) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ToscaDiff(org.eclipse.winery.model.version.ToscaDiff) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) ModelUtilities(org.eclipse.winery.model.tosca.utils.ModelUtilities) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) QName(javax.xml.namespace.QName) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) PolicyTemplateId(org.eclipse.winery.model.ids.definitions.PolicyTemplateId) TPolicyTemplate(org.eclipse.winery.model.tosca.TPolicyTemplate) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) RepositoryFileReference(org.eclipse.winery.repository.common.RepositoryFileReference) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) WineryVersion(org.eclipse.winery.common.version.WineryVersion) Test(org.junit.jupiter.api.Test)

Example 35 with WineryVersion

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());
}
Also used : RelationshipTypeId(org.eclipse.winery.model.ids.definitions.RelationshipTypeId) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) WineryVersion(org.eclipse.winery.common.version.WineryVersion) Test(org.junit.jupiter.api.Test)

Aggregations

WineryVersion (org.eclipse.winery.common.version.WineryVersion)37 Test (org.junit.jupiter.api.Test)19 NodeTypeId (org.eclipse.winery.model.ids.definitions.NodeTypeId)14 DefinitionsChildId (org.eclipse.winery.model.ids.definitions.DefinitionsChildId)12 Produces (javax.ws.rs.Produces)8 IRepository (org.eclipse.winery.repository.backend.IRepository)8 IOException (java.io.IOException)7 POST (javax.ws.rs.POST)7 Path (javax.ws.rs.Path)7 ArrayList (java.util.ArrayList)6 List (java.util.List)6 QName (javax.xml.namespace.QName)6 ServiceTemplateId (org.eclipse.winery.model.ids.definitions.ServiceTemplateId)6 ResourceResult (org.eclipse.winery.repository.rest.resources._support.ResourceResult)6 QNameApiData (org.eclipse.winery.repository.rest.resources.apiData.QNameApiData)6 LinkedHashMap (java.util.LinkedHashMap)5 Response (javax.ws.rs.core.Response)5 Map (java.util.Map)4 Collectors (java.util.stream.Collectors)4 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)4