use of org.eclipse.winery.model.ids.definitions.EntityTypeId 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