protected ObjectNode links(ObjectNode parent, List<Type> types, String appUrl) { ObjectNode content = nodeFactory.objectNode(); types.forEach((it) -> content.set(it.getId(), link(appUrl, it))); parent.set("_links", content); return content; }
@Override public void merge(List<Type> otherContent) { otherContent.forEach((it) -> { if (get(it.getId()) == null) { this.content.add(it); } }); }
/** * Return the {@link Type} with the specified id or {@code null} if no such type * exists. * @param id the ID to find * @return the Type or {@code null} */ public Type get(String id) { return this.content.stream() .filter((it) -> id.equals(it.getId()) || id.equals(it.getStsId())) .findFirst().orElse(null); }
protected void type(ObjectNode parent, TypeCapability capability) { ObjectNode type = nodeFactory.objectNode(); type.put("type", "action"); Type defaultType = capability.getDefault(); if (defaultType != null) { type.put("default", defaultType.getId()); } ArrayNode values = nodeFactory.arrayNode(); values.addAll(capability.getContent().stream().map(this::mapType) .collect(Collectors.toList())); type.set("values", values); parent.set("type", type); }
private String generateTemplatedUri(String appUrl, Type type) { String uri = (appUrl != null) ? appUrl + type.getAction() : type.getAction(); uri = uri + "?type=" + type.getId(); UriTemplate uriTemplate = new UriTemplate(uri, this.templateVariables); return uriTemplate.toString(); }
protected String generateTypeTable(InitializrMetadata metadata, String linkHeader, boolean addTags) { String[][] typeTable = new String[metadata.getTypes().getContent().size() + 1][]; if (addTags) { typeTable[0] = new String[] { linkHeader, "Description", "Tags" }; } else { typeTable[0] = new String[] { linkHeader, "Description" }; } int i = 1; for (Type type : metadata.getTypes().getContent().stream() .sorted(Comparator.comparing(MetadataElement::getId)) .collect(Collectors.toList())) { String[] data = new String[typeTable[0].length]; data[0] = (type.isDefault() ? type.getId() + " *" : type.getId()); data[1] = (type.getDescription() != null) ? type.getDescription() : type.getName(); if (addTags) { data[2] = buildTagRepresentation(type); } typeTable[i++] = data; } return TableGenerator.generate(typeTable); }
@Test void initializeSetsMetadataDefaults() { ProjectRequest request = initProjectRequest(); assertThat(request.getName()).isEqualTo(this.metadata.getName().getContent()); assertThat(request.getType()) .isEqualTo(this.metadata.getTypes().getDefault().getId()); assertThat(request.getDescription()) .isEqualTo(this.metadata.getDescription().getContent()); assertThat(request.getGroupId()) .isEqualTo(this.metadata.getGroupId().getContent()); assertThat(request.getArtifactId()) .isEqualTo(this.metadata.getArtifactId().getContent()); assertThat(request.getVersion()) .isEqualTo(this.metadata.getVersion().getContent()); assertThat(request.getBootVersion()) .isEqualTo(this.metadata.getBootVersions().getDefault().getId()); assertThat(request.getPackaging()) .isEqualTo(this.metadata.getPackagings().getDefault().getId()); }