use of org.platformlayer.core.model.ServiceInfo in project platformlayer by platformlayer.
the class PlatformLayerCliContext method pathToItem.
public PlatformLayerKey pathToItem(ProjectId project, String path) throws PlatformLayerClientException {
String serviceType = null;
String itemType = null;
String itemId = null;
if (path.contains("://")) {
return PlatformLayerKey.parse(path);
}
List<String> components = Lists.newArrayList(path.split("/"));
if (components.size() <= 1) {
throw new IllegalArgumentException("Cannot resolve path: " + path);
}
String head = components.get(0);
{
Map<String, ServiceInfo> services = listServices();
if (services.containsKey(head)) {
serviceType = services.get(head).serviceType;
components.remove(0);
if (components.size() <= 1) {
throw new IllegalArgumentException("Cannot resolve path: " + path);
}
head = components.get(0);
}
}
Multimap<String, ServiceInfo> items = listItemTypes();
if (items.containsKey(head)) {
Collection<ServiceInfo> services = items.get(head);
if (services.size() > 1) {
throw new IllegalArgumentException("Cannot resolve path (ambiguous item type): " + path);
}
ServiceInfo serviceInfo = Iterables.getOnlyElement(services);
itemType = head;
if (serviceType != null) {
if (!Objects.equal(serviceType, serviceInfo.serviceType)) {
throw new IllegalArgumentException("Cannot resolve path (service/item type mismatch): " + path);
}
} else {
serviceType = serviceInfo.serviceType;
}
components.remove(0);
} else {
throw new IllegalArgumentException("Cannot resolve path (unknown item type): " + path);
}
itemId = Joiner.on('/').join(components);
if (serviceType == null) {
throw new IllegalArgumentException("Cannot resolve path (service type not resolved): " + path);
}
if (itemType == null) {
throw new IllegalArgumentException("Cannot resolve path (item type not resolved): " + path);
}
if (Strings.isNullOrEmpty(itemId)) {
throw new IllegalArgumentException("Cannot resolve path (item id not resolved): " + path);
}
FederationKey host = null;
return new PlatformLayerKey(host, project, new ServiceType(serviceType), new ItemType(itemType), new ManagedItemId(itemId));
}
use of org.platformlayer.core.model.ServiceInfo in project platformlayer by platformlayer.
the class PlatformLayerCliContext method listItemTypes.
public Multimap<String, ServiceInfo> listItemTypes() throws PlatformLayerClientException {
Iterable<ServiceInfo> allServices = getAllServiceInfos();
Multimap<String, ServiceInfo> items = HashMultimap.create();
for (ServiceInfo service : allServices) {
for (String itemType : service.getItemTypes()) {
items.put(itemType, service);
}
}
return items;
}
use of org.platformlayer.core.model.ServiceInfo in project platformlayer by platformlayer.
the class PlatformLayerCliContext method listServices.
public Map<String, ServiceInfo> listServices() throws PlatformLayerClientException {
Iterable<ServiceInfo> allServices = getAllServiceInfos();
Map<String, ServiceInfo> services = Maps.newHashMap();
for (ServiceInfo service : allServices) {
services.put(service.getServiceType(), service);
}
return services;
}
use of org.platformlayer.core.model.ServiceInfo in project platformlayer by platformlayer.
the class PlatformLayerCliContext method getAllServiceInfos.
private Iterable<ServiceInfo> getAllServiceInfos() throws PlatformLayerClientException {
PlatformLayerClient client = getPlatformLayerClient();
Iterable<ServiceInfo> allServices = client.listServices(true);
return allServices;
}
use of org.platformlayer.core.model.ServiceInfo in project platformlayer by platformlayer.
the class JaxbContextHelper method getJaxbContext.
public synchronized JAXBContext getJaxbContext(Class<?> forClass) {
if (jaxbContext == null) {
List<Class<?>> javaClasses = Lists.newArrayList();
javaClasses.add(Tags.class);
javaClasses.add(Tag.class);
javaClasses.add(ItemBase.class);
javaClasses.add(ManagedItemCollection.class);
javaClasses.add(JobSchedule.class);
javaClasses.add(PlatformLayerKey.class);
javaClasses.add(ConfigureAction.class);
javaClasses.add(ValidateAction.class);
javaClasses.add(DeleteAction.class);
javaClasses.add(BackupAction.class);
for (ServiceInfo serviceInfo : serviceProviderDictionary.getAllServices()) {
ServiceType serviceType = new ServiceType(serviceInfo.serviceType);
ServiceProvider serviceProvider = serviceProviderDictionary.getServiceProvider(serviceType);
for (ModelClass<?> modelClass : serviceProvider.getModels().all()) {
javaClasses.add(modelClass.getJavaClass());
// String modelNamespace = modelClass.getJaxbHelper().getPrimaryNamespace();
// if (namespace == null) {
// namespace = modelNamespace;
// } else if (!namespace.equals(modelNamespace)) {
// throw new IllegalStateException();
// }
}
for (Class<?> clazz : serviceProvider.getActions()) {
javaClasses.add(clazz);
}
}
try {
jaxbContext = JAXBContext.newInstance(javaClasses.toArray(new Class<?>[javaClasses.size()]));
} catch (JAXBException e) {
throw new IllegalStateException("Unable to build JAXB context", e);
}
}
return jaxbContext;
}
Aggregations