use of org.eclipse.winery.model.ids.definitions.DefinitionsChildId in project winery by eclipse.
the class RestUtils method getCsarOfSelectedResource.
/**
* @param options the set of options that are applicable for exporting a csar
*/
public static Response getCsarOfSelectedResource(final AbstractComponentInstanceResource resource, CsarExportOptions options) {
long start = System.currentTimeMillis();
final CsarExporter exporter = new CsarExporter(RepositoryFactory.getRepository());
Map<String, Object> exportConfiguration = new HashMap<>();
StreamingOutput so = output -> {
try {
// check which options are chosen
if (options.isAddToProvenance()) {
// We wait for the accountability layer to confirm the transaction
String result = exporter.writeCsarAndSaveManifestInProvenanceLayer(resource.getId(), output).get();
LOGGER.debug("Stored state in accountability layer in transaction " + result);
} else if (options.isIncludeDependencies() && resource.getId() instanceof ServiceTemplateId) {
SelfContainmentPackager packager = new SelfContainmentPackager(RepositoryFactory.getRepository());
DefinitionsChildId selfContainedVersion = packager.createSelfContainedVersion(resource.getId());
exporter.writeSelfContainedCsar(RepositoryFactory.getRepository(), selfContainedVersion, output, exportConfiguration);
} else {
exporter.writeCsar(resource.getId(), output, exportConfiguration);
}
long duration = (System.currentTimeMillis() - start) / 1000;
LOGGER.debug("CSAR export lasted {} min {} s", (int) duration / 60, duration % 60);
} catch (Exception e) {
LOGGER.error("Error while exporting CSAR", e);
throw new WebApplicationException(e);
}
};
String contentDisposition = String.format("attachment;filename=\"%s%s\"", resource.getXmlId().getEncoded(), Constants.SUFFIX_CSAR);
return Response.ok().header("Content-Disposition", contentDisposition).type(MimeTypes.MIMETYPE_ZIP).entity(so).build();
}
use of org.eclipse.winery.model.ids.definitions.DefinitionsChildId 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;
}
use of org.eclipse.winery.model.ids.definitions.DefinitionsChildId 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());
}
use of org.eclipse.winery.model.ids.definitions.DefinitionsChildId 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());
}
use of org.eclipse.winery.model.ids.definitions.DefinitionsChildId in project winery by eclipse.
the class RestUtilsWithGitBackendTest method getFlagsOfAReleasedVersion.
@Test
public void getFlagsOfAReleasedVersion() throws Exception {
this.setRevisionTo("origin/plain");
DefinitionsChildId id = new NodeTypeId("http://opentosca.org/nodetypes", "NodeTypeWith5Versions_0.3.4-w3", false);
WineryVersion version = WineryVersionUtils.getCurrentVersionWithAllFlags(id, repository);
assertFalse(version.isReleasable());
assertFalse(version.isEditable());
assertTrue(version.isCurrentVersion());
assertTrue(version.isLatestVersion());
}
Aggregations