de.otto.jsonhome.registry.controller.RegistriesConverter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jsonhome-registry Show documentation
Show all versions of jsonhome-registry Show documentation
Library used to write json-home registries for multiple json-home sources.
The newest version!
/*
* Copyright 2012 Guido Steinacker
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.otto.jsonhome.registry.controller;
import de.otto.jsonhome.registry.store.Link;
import de.otto.jsonhome.registry.store.RegistryRepository;
import java.net.URI;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static de.otto.jsonhome.registry.controller.LinkConverter.linksToJson;
import static java.util.Collections.sort;
/**
* Converter used to convert the registries resource documents.
*
* @author Guido Steinacker
* @since 10.02.13
*/
public class RegistriesConverter {
private RegistriesConverter() {}
public static Map registriesToJson(final URI baseUri, final RegistryRepository repository) {
final Map json = new HashMap<>();
json.put("self", baseUri + "/registries");
json.put("registries", linksToJson(
repositoryLinks(baseUri, repository))
);
return json;
}
private static List repositoryLinks(final URI baseUri, final RegistryRepository repository) {
final List registries = new ArrayList<>();
for (final String registryName : sortedNamesFrom(repository)) {
registries.add(repository
.get(registryName)
.asLinkFor(baseUri)
);
}
return registries;
}
private static List sortedNamesFrom(final RegistryRepository repository) {
final List registryNames = new ArrayList<>(repository.getKnownNames());
sort(registryNames);
return registryNames;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy