@Override public String toString() { QName qn = this.getQName(); return this.getClass().toString() + " / " + qn.toString(); }
/** * Converts the given collection of definition children Ids to a collection of QNames by using the getQName() * method. * <p> * This is required for QNameChooser.tag */ public static Collection<QName> convertDefinitionsChildIdCollectionToQNameCollection(Collection<? extends DefinitionsChildId> col) { Collection<QName> res = new ArrayList<>(); for (DefinitionsChildId id : col) { res.add(id.getQName()); } return res; }
@GET @Path("implementations/") @Produces(MediaType.APPLICATION_JSON) public List<QNameApiData> getImplementations() { return RestUtils.getAllElementsReferencingGivenType(NodeTypeImplementationId.class, this.id.getQName()); }
public String toReadableString() { QName qn = this.getQName(); String name = Util.getEverythingBetweenTheLastDotAndBeforeId(this.getClass()); return String.format("%1$s %3$s in namespace %2$s", name, qn.getNamespaceURI(), qn.getLocalPart()); }
/** * sub-resources **/ @GET @Path("implementations/") @Produces(MediaType.APPLICATION_JSON) public List<QNameApiData> getImplementations() { return RestUtils.getAllElementsReferencingGivenType(NodeTypeImplementationId.class, this.id.getQName()); }
public static String getQNameWithComponentVersionOnly(DefinitionsChildId id) { Matcher m = VERSION_PATTERN.matcher(id.getXmlId().getDecoded()); String componentVersion = ""; if (m.find()) { componentVersion = Objects.nonNull(m.group(COMPONENT_VERSION_GROUP)) ? m.group(COMPONENT_VERSION_GROUP) : ""; } String nameWithoutVersion = getNameWithoutVersion(id.getQName().toString()); if (componentVersion.length() > 0) { nameWithoutVersion += WineryVersion.WINERY_VERSION_SEPARATOR + componentVersion; } return nameWithoutVersion; }
private @NonNull ElementErrorList getElementFromList(@NonNull DefinitionsChildId id) { ElementErrorList element = this.errorList.get(id.getQName()); if (Objects.isNull(element)) { String toscaType = Util.getEverythingBetweenTheLastDotAndBeforeId(id.getClass()); element = new ElementErrorList(toscaType); this.errorList.put(id.getQName(), element); } return element; } }
/** * returns a list of all implementations of a type using the getAllImplementations method */ @GET @Produces(MediaType.APPLICATION_JSON) public Response getJSON() { Collection<? extends DefinitionsChildId> allImplementations = this.getAllImplementations(); List<QNameApiData> res = new ArrayList<>(allImplementations.size()); QNameConverter adapter = new QNameConverter(); for (DefinitionsChildId id : allImplementations) { res.add(adapter.marshal(id.getQName())); } return Response.ok().entity(res).build(); } }
public void writeTOSCA(IRepository repository, DefinitionsChildId id, Map<String, Object> conf, OutputStream outputStream) throws RepositoryCorruptException, IOException { this.processTOSCA(repository, id, new CsarContentProperties(id.getQName().toString()), conf); CsarEntry csarEntry = this.referencesToPathInCSARMap.values().stream() .filter(entry -> entry instanceof DefinitionsBasedCsarEntry) .findFirst() .orElseThrow(() -> new RepositoryCorruptException("Definition not found!")); csarEntry.writeToOutputStream(outputStream); }
public static <X extends DefinitionsChildId> List<QNameApiData> getAllElementsReferencingGivenType(Class<X> clazz, QName qNameOfTheType) { final QNameConverter adapter = new QNameConverter(); return RepositoryFactory.getRepository() .getAllElementsReferencingGivenType(clazz, qNameOfTheType) .stream() .map(id -> adapter.marshal(id.getQName())) .collect(Collectors.toList()); } }
public NameAndQNameApiData(DefinitionsChildId id) { this.name = id.getXmlId().getDecoded(); this.qName = id.getQName(); } }
/** * @return a mapping from file extension to artifact type resources */ // public HashMap<String, ArtifactTypeResource> getFileExtensionMapping() { // HashMap<String, ArtifactTypeResource> res = new HashMap<String, // ArtifactTypeResource>(); // for (ArtifactTypeResource at : this.getArtifactTypeResources()) { // if (at.getAssociatedFileExtension() != null) { // res.put(at.getAssociatedFileExtension(), at); // } // } // return res; // } @GET // should be "QName", but that MIME type is not available. XLink is too // complicated for our setup @Produces(MediaType.TEXT_PLAIN) public Response getArtifactTypeQNameForExtension(@QueryParam("extension") String extension) { if (extension == null) { return Response.status(Status.NOT_ACCEPTABLE).build(); } ArtifactTypeResource artifactType = this.getArtifactTypeForExtension(extension); Response res; if (artifactType == null) { res = Response.status(Status.NOT_FOUND).build(); } else { res = Response.ok().entity(artifactType.getId().getQName().toString()).build(); } return res; }
public InputStream convertX2Y(DefinitionsChildId id) throws MultiException { Path path = Utils.getTmpDir(Paths.get(id.getQName().getLocalPart())); convertX2Y(repository.getDefinitions(id), path); return Utils.zipPath(path); }
private List<NamespaceAndDefinedLocalNamesForAngular> getGroupedListOfIds(SortedSet<? extends DefinitionsChildId> allDefinitionsChildIds, String full, String includeVersions) { Map<Namespace, ? extends List<? extends DefinitionsChildId>> groupedIds = allDefinitionsChildIds.stream().collect(Collectors.groupingBy(DefinitionsChildId::getNamespace)); return groupedIds.keySet().stream() .sorted() .map(namespace -> { List<LocalNameForAngular> names = groupedIds.get(namespace).stream() .map(definition -> { Definitions fullDefinition = null; if (Objects.nonNull(full)) { fullDefinition = getFullComponentData(definition); } String qName = definition.getQName().toString(); String id = definition.getXmlId().toString(); if ("componentVersionOnly".equals(includeVersions)) { qName = VersionUtils.getQNameWithComponentVersionOnly(definition); id = qName.split("}")[1]; } return new LocalNameForAngular(qName, id, fullDefinition); }) .distinct() .collect(Collectors.toList()); return new NamespaceAndDefinedLocalNamesForAngular(namespace, names); }) .collect(Collectors.toList()); }
public static void commit(DefinitionsChildId componentToCommit, String commitMessagePrefix) throws GitAPIException { if (RepositoryFactory.getRepository() instanceof GitBasedRepository) { GitBasedRepository gitRepo = (GitBasedRepository) RepositoryFactory.getRepository(); List<String> filePatternsToCommit = new ArrayList<>(); if (gitRepo.hasChangesInFile(BackendUtils.getRefOfDefinitions(componentToCommit))) { /*WineryVersion predecessor = BackendUtils.getPredecessor(componentToCommit); ToscaDiff diff = BackendUtils.compare(componentToCommit, predecessor); String changeLog = diff.getChangeLog(); // get changelog.md and append changeLog*/ filePatternsToCommit.add(Util.getPathInsideRepo(componentToCommit)); gitRepo.addCommit(filePatternsToCommit.toArray(new String[filePatternsToCommit.size()]), commitMessagePrefix + " " + componentToCommit.getQName()); } } else { throw new RuntimeException("Repository does not support git!"); } } }
/** * Used by children to implement getListOfAllInstances() */ protected SortedSet<Select2OptGroup> getListOfAllInstances(Class<? extends DefinitionsChildId> clazz) throws RepositoryCorruptException { Select2DataWithOptGroups data = new Select2DataWithOptGroups(); Collection<? extends DefinitionsChildId> instanceIds = RepositoryFactory.getRepository().getAllElementsReferencingGivenType(clazz, this.id.getQName()); for (DefinitionsChildId instanceId : instanceIds) { String groupText = instanceId.getNamespace().getDecoded(); String text = BackendUtils.getName(instanceId); data.add(groupText, instanceId.getQName().toString(), text); } return data.asSortedSet(); }
public String convertDefinitionsChildToYaml(DefinitionsChildId id) throws MultiException { Path path = Utils.getTmpDir(Paths.get(id.getQName().getLocalPart())); convertX2Y(repository.getDefinitions(id), path); // convention: single file in root contains the YAML support // TODO: Links in the YAML should be changed to real links into Winery Optional<Path> rootYamlFile; try { return Files.find(path, 1, (filePath, basicFileAttributes) -> filePath.getFileName().toString().endsWith(".yml")) .findAny() .map(p -> { try { return new String(Files.readAllBytes(p), StandardCharsets.UTF_8); } catch (IOException e) { LOGGER.debug("Could not read root file", e); return "Could not read root file"; } }) .orElseThrow(() -> { MultiException multiException = new MultiException(); multiException.add(new WineryRepositoryException("Root YAML file not found.")); return multiException; }); } catch (IOException e) { MultiException multiException = new MultiException(); multiException.add(new WineryRepositoryException("Root YAML file not found.", e)); throw multiException; } }
private List<ComponentId> getListOfIds(SortedSet<? extends DefinitionsChildId> allDefinitionsChildIds, boolean supportsNameAttribute, String full, String includeVersions) { return allDefinitionsChildIds.stream() .sorted() .map(id -> { String name = id.getXmlId().getDecoded(); Definitions definitions = null; WineryVersion version = null; if (supportsNameAttribute) { AbstractComponentInstanceResource componentInstanceResource = AbstractComponentsResource.getComponentInstanceResource(id); name = ((IHasName) componentInstanceResource).getName(); } if (Objects.nonNull(full)) { definitions = getFullComponentData(id); } if (Objects.nonNull(includeVersions)) { version = VersionUtils.getVersion(id.getXmlId().getDecoded()); } return new ComponentId(id.getXmlId().getDecoded(), name, id.getNamespace().getDecoded(), id.getQName(), definitions, version); }) .collect(Collectors.toList()); }
@Override public Definitions getDefinitions(DefinitionsChildId id) { for (WebResource wr: this.repositoryResources) { String path = Util.getUrlPath(id); Definitions definitions = WineryRepositoryClient.getDefinitions(wr.path(path)); if (definitions == null) { // in case of an error, just try the next one continue; } TExtensibleElements element = definitions.getElement(); if (element instanceof TEntityType) { this.cache((TEntityType) element, id.getQName()); return definitions; } } return new Definitions(); }
public VisualsApiData(GenericVisualAppearanceResource visuals) { IRepository repository = RepositoryFactory.getRepository(); DefinitionsChildId parent = (DefinitionsChildId) visuals.getId().getParent(); this.color = visuals.getColor(); this.typeId = parent.getQName(); this.pattern = repository.getNamespaceManager().isPatternNamespace(parent.getNamespace().getDecoded()); RepositoryFileReference iconRef = new RepositoryFileReference(visuals.getId(), Filename.FILENAME_SMALL_ICON); if (repository.exists(iconRef)) { iconUrl = visuals.getAbsoluteURL() + "16x16"; } RepositoryFileReference imageRef = new RepositoryFileReference(visuals.getId(), Filename.FILENAME_BIG_ICON); if (repository.exists(imageRef)) { imageUrl = visuals.getAbsoluteURL() + "50x50"; } }