use of org.eclipse.winery.repository.backend.filebased.NamespaceProperties in project winery by eclipse.
the class TopologyTemplateResource method getNewVersionList.
@GET
@Path("newversions")
@Produces(MediaType.APPLICATION_JSON)
public List<NewVersionListElement> getNewVersionList() {
IRepository repository = RepositoryFactory.getRepository();
Map<QName, TNodeType> nodeTypes = repository.getQNameToElementMapping(NodeTypeId.class);
Map<QName, List<WineryVersion>> versionElements = new HashMap<>();
for (TNodeTemplate node : this.topologyTemplate.getNodeTemplates()) {
if (nodeTypes.containsKey(node.getType())) {
NodeTypeId nodeTypeId = new NodeTypeId(node.getType());
if (!versionElements.containsKey(nodeTypeId.getQName())) {
List<WineryVersion> versionList = WineryVersionUtils.getAllVersionsOfOneDefinition(nodeTypeId, repository).stream().filter(wineryVersion -> {
QName qName = VersionSupport.getDefinitionInTheGivenVersion(nodeTypeId, wineryVersion).getQName();
NamespaceProperties namespaceProperties = repository.getNamespaceManager().getNamespaceProperties(qName.getNamespaceURI());
return !(namespaceProperties.isGeneratedNamespace() || ModelUtilities.isFeatureType(qName, nodeTypes));
}).collect(Collectors.toList());
versionElements.put(nodeTypeId.getQName(), versionList);
}
}
}
return versionElements.entrySet().stream().map(qNameListEntry -> new NewVersionListElement(qNameListEntry.getKey(), qNameListEntry.getValue())).collect(Collectors.toList());
}
use of org.eclipse.winery.repository.backend.filebased.NamespaceProperties in project winery by eclipse.
the class MultiRepository method fixNamespaces.
private void fixNamespaces(IRepository repository) {
SortedSet<DefinitionsChildId> defChildren = repository.getAllDefinitionsChildIds();
Collection<NamespaceProperties> namespaceProperties = new ArrayList<>();
for (DefinitionsChildId value : defChildren) {
namespaceProperties.add(new NamespaceProperties(value.getNamespace().getDecoded(), value.getNamespace().getDecoded().replace(".", ""), "", false));
}
repository.getNamespaceManager().addAllPermanent(namespaceProperties);
}
use of org.eclipse.winery.repository.backend.filebased.NamespaceProperties 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 = targetRepository.getNamespaceManager();
Path properties = rootPath.resolve(CsarExporter.PATH_TO_NAMESPACES_PROPERTIES);
Path json = rootPath.resolve(CsarExporter.PATH_TO_NAMESPACES_JSON);
if (Files.exists(properties) || Files.exists(json)) {
NamespaceManager localNamespaceManager;
if (Files.exists(properties)) {
PropertiesConfiguration pconf = new PropertiesConfiguration();
try (final BufferedReader propertyReader = Files.newBufferedReader(properties)) {
pconf.read(propertyReader);
localNamespaceManager = new ConfigurationBasedNamespaceManager(pconf);
} catch (IOException | ConfigurationException e) {
CsarImporter.LOGGER.debug(e.getMessage(), e);
return;
}
} else {
localNamespaceManager = new JsonBasedNamespaceManager(json.toFile());
}
for (String s : localNamespaceManager.getAllNamespaces().keySet()) {
boolean addToStorage = false;
String namespace = s;
if (namespaceManager.hasPermanentProperties(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 = localNamespaceManager.getPrefix(namespace);
namespaceManager.setNamespaceProperties(namespace, new NamespaceProperties(namespace, prefix));
}
}
}
}
use of org.eclipse.winery.repository.backend.filebased.NamespaceProperties in project winery by eclipse.
the class EnhancementUtils method generateNewGeneratedNamespace.
private static String generateNewGeneratedNamespace(QName qName) {
NamespaceManager namespaceManager = RepositoryFactory.getRepository().getNamespaceManager();
String namespace = qName.getNamespaceURI().concat(GENERATED_NS_SUFFIX);
NamespaceProperties namespaceProperties = namespaceManager.getNamespaceProperties(namespace);
namespaceProperties.setGeneratedNamespace(true);
namespaceManager.setNamespaceProperties(namespace, namespaceProperties);
return namespace;
}
use of org.eclipse.winery.repository.backend.filebased.NamespaceProperties in project winery by eclipse.
the class JsonBasedMultiNamespaceManager method loadNamespacePropertiesFromFile.
private Map<IRepository, Map<String, NamespaceProperties>> loadNamespacePropertiesFromFile() {
Map<IRepository, Map<String, NamespaceProperties>> result = new HashMap<>();
Map<String, NamespaceProperties> nsProps = new HashMap<>();
for (IRepository repo : this.repository.getRepositories()) {
RepositoryFileReference ref = BackendUtils.getRefOfJsonConfiguration(new NamespacesId());
File file = repo.ref2AbsolutePath(ref).toFile();
try {
if (file.exists()) {
TypeReference<HashMap<String, NamespaceProperties>> hashMapTypeReference = new TypeReference<HashMap<String, NamespaceProperties>>() {
};
nsProps = JacksonProvider.mapper.readValue(file, hashMapTypeReference);
}
} catch (IOException e) {
LOGGER.debug("Error while loading the namespace file.", e);
throw new RuntimeException();
}
result.put(repo, nsProps);
}
return result;
}
Aggregations