use of org.eclipse.winery.model.ids.GenericId in project winery by eclipse.
the class YamlRepository method exists.
/**
* Checks if YAML Definition exists Artifact Templates are searched in Type
*
* @param id generic id of target
* @return boolean if target exists
*/
@Override
public boolean exists(GenericId id) {
Path targetPath = id2AbsolutePath(id);
if (id instanceof ArtifactTemplateId) {
GenericId convertedId = convertGenericId(id);
if (convertedId != null) {
String convertedFilename = BackendUtils.getFileNameOfDefinitions((DefinitionsChildId) convertedId);
targetPath = targetPath.resolve(convertedFilename);
return artifactTemplateExistsInType(targetPath, ((ArtifactTemplateId) id).getQName());
}
}
return Files.exists(targetPath);
}
use of org.eclipse.winery.model.ids.GenericId in project winery by eclipse.
the class YamlRepository method ref2AbsolutePath.
/**
* Converts RepositoryFileReference to compatible YAML File
*
* @param ref RepositoryFileReference
* @return compatible Path
*/
@Override
public Path ref2AbsolutePath(RepositoryFileReference ref) {
Path resultPath = super.ref2AbsolutePath(ref);
GenericId convertedId = convertGenericId(ref.getParent());
if (convertedId != null) {
if (convertedId instanceof DefinitionsChildId) {
String convertedFilename = BackendUtils.getFileNameOfDefinitions((DefinitionsChildId) convertedId);
return resultPath.resolve(convertedFilename);
}
}
return resultPath;
}
use of org.eclipse.winery.model.ids.GenericId in project winery by eclipse.
the class AbstractFileBasedRepository method getContainedFiles.
@Override
public SortedSet<RepositoryFileReference> getContainedFiles(GenericId id) {
Path dir = this.id2AbsolutePath(id);
SortedSet<RepositoryFileReference> res = new TreeSet<>();
if (!Files.exists(dir)) {
return res;
}
assert (Files.isDirectory(dir));
final OnlyNonHiddenFiles onlyNonHiddenFiles = new OnlyNonHiddenFiles();
try {
Files.walk(dir).filter(f -> {
try {
return onlyNonHiddenFiles.accept(f);
} catch (IOException e) {
LOGGER.debug("Error during crawling", e);
return false;
}
}).map(f -> {
final Path relativePath = dir.relativize(f.getParent());
if (relativePath.toString().isEmpty()) {
return new RepositoryFileReference(id, f.getFileName().toString());
} else {
return new RepositoryFileReference(id, relativePath, f.getFileName().toString());
}
}).forEach(res::add);
} catch (IOException e1) {
LOGGER.debug("Error during crawling", e1);
}
return res;
}
use of org.eclipse.winery.model.ids.GenericId in project winery by eclipse.
the class YamlRepository method deleteArtifact.
/**
* Deletes artifacts from there referenced type
*
* @param id Artifact Template id
*/
private void deleteArtifact(ArtifactTemplateId id) {
if (getNameOfTypeFromArtifactName(id.getQName().getLocalPart()).equalsIgnoreCase("Cache")) {
super.forceDelete(id);
} else {
Path targetPath = id2AbsolutePath(id);
GenericId convertedId = convertGenericId(id);
if (convertedId != null) {
if (convertedId instanceof DefinitionsChildId) {
String convertedFilename = BackendUtils.getFileNameOfDefinitions((DefinitionsChildId) convertedId);
targetPath = targetPath.resolve(convertedFilename);
}
}
if (Files.exists(targetPath)) {
try {
YTServiceTemplate nodeType = readServiceTemplate(targetPath);
String targetArtifactName = getNameOfArtifactFromArtifactName(id.getQName().getLocalPart());
if (getTypeFromArtifactName(id.getQName().getLocalPart()).equalsIgnoreCase("nodetypes")) {
Map<String, YTArtifactDefinition> artifacts = nodeType.getNodeTypes().entrySet().iterator().next().getValue().getArtifacts();
nodeType.getNodeTypes().entrySet().iterator().next().setValue(removeImplementation(nodeType.getNodeTypes().entrySet().iterator().next().getValue(), targetArtifactName));
artifacts.remove(targetArtifactName);
nodeType.getNodeTypes().entrySet().iterator().next().getValue().setArtifacts(artifacts);
} else {
nodeType.getRelationshipTypes().entrySet().iterator().next().setValue(removeRelationshipArtifact(nodeType.getRelationshipTypes().entrySet().iterator().next().getValue(), targetArtifactName));
}
YamlWriter writer = new YamlWriter();
InputStream output = writer.writeToInputStream(nodeType);
writeInputStreamToPath(targetPath, output);
} catch (Exception e) {
LOGGER.error("Error deleting file: {}", e.getMessage(), e);
}
}
}
}
use of org.eclipse.winery.model.ids.GenericId in project winery by eclipse.
the class RestUtils method getZippedContents.
/**
* Zips the folder reference given by the id. As filename the parent id is used.
*
* @param id the id of the folder
* @param name the name of the result zip (including.zip)
*/
public static Response getZippedContents(final GenericId id, String name) {
StreamingOutput so = output -> {
try {
RepositoryFactory.getRepository().getZippedContents(id, output);
} catch (Exception e) {
throw new WebApplicationException(e);
}
};
String sb = "attachment;filename=\"" + name + "\"";
return Response.ok().header("Content-Disposition", sb).type(MimeTypes.MIMETYPE_ZIP).entity(so).build();
}
Aggregations