use of org.eclipse.winery.repository.backend.NamespaceManager in project winery by eclipse.
the class CsarImporter method importNamespacePrefixes.
/**
* Import namespace prefixes. This is kind of a quick hack. TODO: during the import, the prefixes should be
* extracted using JAXB and stored in the NamespacesResource
*
* @param rootPath the root path of the extracted CSAR
*/
private void importNamespacePrefixes(Path rootPath) {
NamespaceManager namespaceManager = RepositoryFactory.getRepository().getNamespaceManager();
Path properties = rootPath.resolve(CsarExporter.PATH_TO_NAMESPACES_PROPERTIES);
if (Files.exists(properties)) {
PropertiesConfiguration pconf;
try {
pconf = new PropertiesConfiguration(properties.toFile());
} catch (ConfigurationException e) {
CsarImporter.LOGGER.debug(e.getMessage(), e);
return;
}
Iterator<String> namespaces = pconf.getKeys();
while (namespaces.hasNext()) {
boolean addToStorage = false;
String namespace = namespaces.next();
if (namespaceManager.hasPrefix(namespace)) {
String storedPrefix = namespaceManager.getPrefix(namespace);
// QUICK HACK to check whether the prefix is a generated one
// We assume we know the internal generation routine
Matcher m = CsarImporter.GENERATED_PREFIX_PATTERN.matcher(storedPrefix);
if (m.matches()) {
// the stored prefix is a generated one
// replace it by the one stored in the exported properties
addToStorage = true;
}
} else {
addToStorage = true;
}
if (addToStorage) {
String prefix = pconf.getString(namespace);
namespaceManager.setPrefix(namespace, prefix);
}
}
}
}
use of org.eclipse.winery.repository.backend.NamespaceManager in project winery by eclipse.
the class PropertiesDefinitionResource method onJsonPost.
@POST
@Consumes(MediaType.APPLICATION_JSON)
public Response onJsonPost(PropertiesDefinitionResourceApiData data) {
if (data.selectedValue == PropertiesDefinitionEnum.Element || data.selectedValue == PropertiesDefinitionEnum.Type) {
// first of all, remove Winery's Properties definition (if it exists)
ModelUtilities.removeWinerysPropertiesDefinition(this.getEntityType());
// replace old properties definition by new one
PropertiesDefinition def = new PropertiesDefinition();
if (data.propertiesDefinition.getElement() != null) {
def.setElement(data.propertiesDefinition.getElement());
} else if (data.propertiesDefinition.getType() != null) {
def.setType(data.propertiesDefinition.getType());
} else {
return Response.status(Status.BAD_REQUEST).entity("Wrong data submitted!").build();
}
this.getEntityType().setPropertiesDefinition(def);
List<String> errors = new ArrayList<>();
BackendUtils.deriveWPD(this.getEntityType(), errors);
// currently the errors are just logged
for (String error : errors) {
PropertiesDefinitionResource.LOGGER.debug(error);
}
return RestUtils.persist(this.parentRes);
} else if (data.selectedValue == PropertiesDefinitionEnum.Custom) {
TEntityType et = this.parentRes.getEntityType();
// clear current properties definition
et.setPropertiesDefinition(null);
// create winery properties definition and persist it
ModelUtilities.replaceWinerysPropertiesDefinition(et, data.winerysPropertiesDefinition);
String namespace = data.winerysPropertiesDefinition.getNamespace();
NamespaceManager namespaceManager = RepositoryFactory.getRepository().getNamespaceManager();
if (!namespaceManager.hasPrefix(namespace)) {
namespaceManager.addNamespace(namespace);
}
return RestUtils.persist(this.parentRes);
}
return Response.status(Status.BAD_REQUEST).entity("Wrong data submitted!").build();
}
Aggregations