Search in sources :

Example 11 with WineryVersion

use of org.eclipse.winery.common.version.WineryVersion in project winery by eclipse.

the class RestUtils method releaseVersion.

public static Response releaseVersion(DefinitionsChildId releasableComponent) {
    ResourceResult result = new ResourceResult();
    final IRepository repository = RepositoryFactory.getRepository();
    WineryVersion version = WineryVersionUtils.getCurrentVersionWithAllFlags(releasableComponent, repository);
    if (version.isReleasable()) {
        if (repository instanceof GitBasedRepository) {
            try {
                freezeVersion(releasableComponent);
                version.setWorkInProgressVersion(0);
                String newId = releasableComponent.getNameWithoutVersion() + WineryVersion.WINERY_NAME_FROM_VERSION_SEPARATOR + version;
                DefinitionsChildId newComponent = BackendUtils.getDefinitionsChildId(releasableComponent.getClass(), releasableComponent.getNamespace().getDecoded(), newId, false);
                result = duplicate(releasableComponent, newComponent);
                BackendUtils.commit(newComponent, "Release", repository);
            } catch (GitAPIException e) {
                result.setStatus(Status.INTERNAL_SERVER_ERROR);
            }
        } else {
            result.setStatus(Status.INTERNAL_SERVER_ERROR);
        }
    } else {
        result.setStatus(Status.BAD_REQUEST);
    }
    return result.getResponse();
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) ResourceResult(org.eclipse.winery.repository.rest.resources._support.ResourceResult) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) IRepository(org.eclipse.winery.repository.backend.IRepository) GitBasedRepository(org.eclipse.winery.repository.backend.filebased.GitBasedRepository) WineryVersion(org.eclipse.winery.common.version.WineryVersion)

Example 12 with WineryVersion

use of org.eclipse.winery.common.version.WineryVersion in project winery by eclipse.

the class RestUtils method rename.

public static ResourceResult rename(DefinitionsChildId oldId, DefinitionsChildId newId) {
    ResourceResult result = new ResourceResult();
    IRepository repo = RepositoryFactory.getRepository();
    WineryVersion version = oldId.getVersion();
    DefinitionsChildId id = newId;
    if (version.toString().length() > 0) {
        // ensure that the version isn't changed by the user
        String componentName = newId.getNameWithoutVersion() + WineryVersion.WINERY_NAME_FROM_VERSION_SEPARATOR + version;
        id = BackendUtils.getDefinitionsChildId(oldId.getClass(), newId.getNamespace().getDecoded(), componentName, false);
    }
    // If a definition was not committed yet, it is renamed, otherwise duplicate the definition.
    if (repo.hasChangesInFile(oldId)) {
        try {
            repo.rename(oldId, id);
        } catch (IOException e) {
            LOGGER.error(e.getMessage(), e);
            result.setStatus(Status.INTERNAL_SERVER_ERROR);
            result.setMessage(e.getMessage());
            return result;
        }
    } else {
        result = duplicate(oldId, id);
        if (result.isSuccess()) {
            result = freezeVersion(id);
        }
    }
    URI uri = RestUtils.getAbsoluteURI(id);
    result.setUri(uri);
    result.setStatus(Status.CREATED);
    return result;
}
Also used : ResourceResult(org.eclipse.winery.repository.rest.resources._support.ResourceResult) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) IOException(java.io.IOException) IRepository(org.eclipse.winery.repository.backend.IRepository) URI(java.net.URI) WineryVersion(org.eclipse.winery.common.version.WineryVersion)

Example 13 with WineryVersion

use of org.eclipse.winery.common.version.WineryVersion in project winery by eclipse.

the class VersionSupportTest method getVersionWithLeadingDashButNoComponentVersion.

@Test
public void getVersionWithLeadingDashButNoComponentVersion() {
    DefinitionsChildId id = new ServiceTemplateId("http://example.org/tosca/versioning", "myServiceTemplate_-w1-wip5", false);
    WineryVersion version = id.getVersion();
    assertEquals("", version.getComponentVersion());
    assertEquals(1, version.getWineryVersion());
    assertEquals(5, version.getWorkInProgressVersion());
}
Also used : DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) WineryVersion(org.eclipse.winery.common.version.WineryVersion) Test(org.junit.jupiter.api.Test)

Example 14 with WineryVersion

use of org.eclipse.winery.common.version.WineryVersion in project winery by eclipse.

the class VersionSupportTest method getVersion.

@Test
public void getVersion() {
    String componentVersion = "1.0.0";
    int wineryVersion = 6;
    int wipVersion = 3;
    DefinitionsChildId id = getDefinitionChildId("http://example.org/tosca/versions", "myElement", componentVersion, wineryVersion, wipVersion);
    WineryVersion version = id.getVersion();
    assertEquals(componentVersion, version.getComponentVersion());
    assertEquals(wineryVersion, version.getWineryVersion());
    assertEquals(wipVersion, version.getWorkInProgressVersion());
}
Also used : DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) WineryVersion(org.eclipse.winery.common.version.WineryVersion) Test(org.junit.jupiter.api.Test)

Example 15 with WineryVersion

use of org.eclipse.winery.common.version.WineryVersion in project winery by eclipse.

the class ServiceTemplateResource method createNewStatefulVersion.

@POST()
@Path("createnewstatefulversion")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response createNewStatefulVersion() {
    LOGGER.debug("Creating new stateful version of Service Template {}...", this.getId());
    ServiceTemplateId id = (ServiceTemplateId) this.getId();
    WineryVersion version = id.getVersion();
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd-HHmmss");
    WineryVersion newVersion = new WineryVersion("stateful-" + version.toString() + "-" + dateFormat.format(new Date()), 1, 0);
    ServiceTemplateId newId = new ServiceTemplateId(id.getNamespace().getDecoded(), id.getNameWithoutVersion() + WineryVersion.WINERY_NAME_FROM_VERSION_SEPARATOR + newVersion.toString(), 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();
}
Also used : ResourceResult(org.eclipse.winery.repository.rest.resources._support.ResourceResult) QNameApiData(org.eclipse.winery.repository.rest.resources.apiData.QNameApiData) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) WineryVersion(org.eclipse.winery.common.version.WineryVersion) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

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