use of org.eclipse.winery.model.tosca.TPlan.PlanModelReference in project winery by eclipse.
the class PlansResource method setPlanModelReference.
static void setPlanModelReference(TPlan plan, PlanId planId, String fileName) {
PlanModelReference pref = new PlanModelReference();
// Set path relative to Definitions/ path inside CSAR.
pref.setReference("../" + Util.getUrlPath(planId) + fileName);
plan.setPlanModelReference(pref);
}
use of org.eclipse.winery.model.tosca.TPlan.PlanModelReference in project winery by eclipse.
the class CsarImporter method adjustServiceTemplate.
/**
* In case plans are provided, the plans are imported into Winery's storage
*
* @param rootPath the root path of the extracted csar
* @param tmf the TOSCAMetaFile object used to determine the mime type of the plan
* @param wid Winery's internal id of the service template
* @param st the the service template to be imported {@inheritDoc}
*/
private void adjustServiceTemplate(Path rootPath, TOSCAMetaFile tmf, ServiceTemplateId wid, TServiceTemplate st, final List<String> errors) {
List<TPlan> plans = st.getPlans();
if (plans != null) {
for (TPlan plan : plans) {
PlanModelReference refContainer = plan.getPlanModelReference();
if (refContainer != null) {
String ref = refContainer.getReference();
if (ref != null) {
// URLs are stored encoded -> undo the encoding
ref = EncodingUtil.URLdecode(ref);
URI refURI;
try {
refURI = new URI(ref);
} catch (URISyntaxException e) {
errors.add(String.format("Invalid URI %1$s", ref));
continue;
}
if (refURI.isAbsolute()) {
// We have to do nothing
continue;
}
Path path = rootPath.resolve(ref);
if (!Files.exists(path)) {
// possibly, the reference is relative to the Definitions subfolder
// COS01 does not make any explicit statement how to resolve the reference here
path = rootPath.resolve("Definitions").resolve(ref);
if (!Files.exists(path)) {
errors.add(String.format("Plan reference %1$s not found", ref));
// we quickly remove the reference to reflect the not-found in the data
refContainer.setReference(null);
continue;
}
}
PlansId plansId = new PlansId(wid);
PlanId pid = new PlanId(plansId, new XmlId(plan.getId(), false));
if (Files.isDirectory(path)) {
errors.add(String.format("Reference %1$s is a directory and Winery currently does not support importing directories", ref));
continue;
}
RepositoryFileReference fref = new RepositoryFileReference(pid, path.getFileName().toString());
importFile(path, fref, tmf, rootPath, errors);
// file is imported
// Adjust the reference
refContainer.setReference("../" + Util.getUrlPath(fref));
}
}
}
}
}
Aggregations