use of org.eclipse.winery.repository.datatypes.ids.elements.ArtifactTemplateSourceDirectoryId in project winery by eclipse.
the class BackendUtilsTest method repositoryFileReferenceWithoutSubdirectoryCorrectlyCreated.
@Test
public void repositoryFileReferenceWithoutSubdirectoryCorrectlyCreated() {
ArtifactTemplateId artifactTemplateId = new ArtifactTemplateId("http://www.example.org", "at", false);
ArtifactTemplateSourceDirectoryId artifactTemplateSourceDirectoryId = new ArtifactTemplateSourceDirectoryId(artifactTemplateId);
final RepositoryFileReference repositoryFileReference = BackendUtils.getRepositoryFileReference(Paths.get("main"), Paths.get("main", "file.txt"), artifactTemplateSourceDirectoryId);
assertEquals(artifactTemplateSourceDirectoryId, repositoryFileReference.getParent());
assertEquals(Optional.empty(), repositoryFileReference.getSubDirectory());
assertEquals("file.txt", repositoryFileReference.getFileName());
}
use of org.eclipse.winery.repository.datatypes.ids.elements.ArtifactTemplateSourceDirectoryId in project winery by eclipse.
the class BackendUtilsTest method repositoryFileReferenceWithSubdirectoryCorrectlyCreated.
@Test
public void repositoryFileReferenceWithSubdirectoryCorrectlyCreated() {
ArtifactTemplateId artifactTemplateId = new ArtifactTemplateId("http://www.example.org", "at", false);
ArtifactTemplateSourceDirectoryId artifactTemplateSourceDirectoryId = new ArtifactTemplateSourceDirectoryId(artifactTemplateId);
final Path subDirectories = Paths.get("d1", "d2");
final RepositoryFileReference repositoryFileReference = BackendUtils.getRepositoryFileReference(Paths.get("main"), Paths.get("main", "d1", "d2", "file.txt"), artifactTemplateSourceDirectoryId);
assertEquals(artifactTemplateSourceDirectoryId, repositoryFileReference.getParent());
assertEquals(Optional.of(subDirectories), repositoryFileReference.getSubDirectory());
assertEquals("file.txt", repositoryFileReference.getFileName());
}
use of org.eclipse.winery.repository.datatypes.ids.elements.ArtifactTemplateSourceDirectoryId in project winery by eclipse.
the class GenericArtifactsResource method generateImplementationArtifact.
/**
* Generates the implementation artifact using the implementation artifact generator. Also sets the properties
* according to the requirements of OpenTOSCA.
*/
private Response generateImplementationArtifact(String interfaceName, String javaPackage, UriInfo uriInfo, ArtifactTemplateId artifactTemplateId) {
assert (this instanceof ImplementationArtifactsResource);
IRepository repository = RepositoryFactory.getRepository();
QName type = RestUtils.getType(this.res);
EntityTypeId typeId = getTypeId(type).orElseThrow(IllegalStateException::new);
TInterface i = findInterface(typeId, interfaceName).orElseThrow(IllegalStateException::new);
Path workingDir;
try {
workingDir = Files.createTempDirectory("winery");
} catch (IOException e2) {
LOGGER.debug("Could not create temporary directory", e2);
return Response.serverError().entity("Could not create temporary directory").build();
}
URI artifactTemplateFilesUri = uriInfo.getBaseUri().resolve(RestUtils.getAbsoluteURL(artifactTemplateId)).resolve("files");
URL artifactTemplateFilesUrl;
try {
artifactTemplateFilesUrl = artifactTemplateFilesUri.toURL();
} catch (MalformedURLException e2) {
LOGGER.debug("Could not convert URI to URL", e2);
return Response.serverError().entity("Could not convert URI to URL").build();
}
String name = this.generateName(typeId, interfaceName);
Generator gen = new Generator(i, javaPackage, artifactTemplateFilesUrl, name, workingDir.toFile());
Path targetPath;
try {
targetPath = gen.generateProject();
} catch (Exception e) {
LOGGER.debug("IA generator failed", e);
return Response.serverError().entity("IA generator failed").build();
}
DirectoryId fileDir = new ArtifactTemplateSourceDirectoryId(artifactTemplateId);
try {
BackendUtils.importDirectory(targetPath, repository, fileDir);
} catch (IOException e) {
throw new WebApplicationException(e);
}
// clean up
FileUtils.forceDelete(workingDir);
this.storeProperties(artifactTemplateId, typeId, name);
URI url = uriInfo.getBaseUri().resolve(Util.getUrlPath(artifactTemplateId));
return Response.created(url).build();
}
Aggregations