use of org.platformlayer.ids.ItemType in project platformlayer by platformlayer.
the class ServiceProviderDirectoryBase method getModelClass.
@Override
public <T extends ItemBase> ModelClass<T> getModelClass(Class<T> itemClass) {
ModelClass<T> modelClass = javaClassToModelClass.get(itemClass);
if (modelClass == null) {
// Fallback to matching on XML info
ElementInfo elementInfo = XmlHelper.getXmlElementInfo(itemClass);
if (elementInfo != null) {
ServiceProvider serviceProvider = serviceProvidersByNamespace.get(elementInfo.namespace);
if (serviceProvider != null) {
ItemType itemType = new ItemType(elementInfo.elementName);
modelClass = (ModelClass<T>) serviceProvider.getModelClass(itemType);
}
}
}
return modelClass;
}
use of org.platformlayer.ids.ItemType in project platformlayer by platformlayer.
the class PlatformLayerKey method parse.
public static PlatformLayerKey parse(String s) {
if (!s.contains("://")) {
int slashCount = 0;
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (c == '/') {
slashCount++;
}
}
String extraSlashes = "";
if (slashCount < 4) {
extraSlashes = Strings.repeat("/", 4 - slashCount);
}
s = SCHEME + "://" + extraSlashes + s;
}
URI uri;
try {
uri = new URI(s);
} catch (URISyntaxException e) {
throw new IllegalArgumentException("Error parsing URI", e);
}
if (!Objects.equal(SCHEME, uri.getScheme())) {
throw new IllegalArgumentException();
}
FederationKey hostKey = null;
String host = uri.getHost();
if (!Strings.isNullOrEmpty(host)) {
hostKey = FederationKey.build(host);
}
String path = uri.getPath();
if (path.startsWith("/")) {
path = path.substring(1);
}
ArrayList<String> components = Lists.newArrayList(Splitter.on('/').split(path));
if (components.size() < 4) {
throw new IllegalArgumentException();
}
String componentProject = components.get(0);
ProjectId project = !Strings.isNullOrEmpty(componentProject) ? new ProjectId(componentProject) : null;
String serviceComponent = components.get(1);
ServiceType serviceType = !Strings.isNullOrEmpty(serviceComponent) ? new ServiceType(serviceComponent) : null;
ItemType itemType = new ItemType(components.get(2));
ManagedItemId itemId = new ManagedItemId(Joiner.on("/").join(components.subList(3, components.size())));
return new PlatformLayerKey(hostKey, project, serviceType, itemType, itemId);
}
use of org.platformlayer.ids.ItemType in project platformlayer by platformlayer.
the class ServiceProviderBase method resolveKey.
private PlatformLayerKey resolveKey(PlatformLayerKey key) throws OpsException {
if (key.getServiceType() == null) {
ItemType itemType = key.getItemType();
ServiceType serviceType = OpsContext.get().getOpsSystem().getServiceType(itemType);
key = key.withServiceType(serviceType);
}
if (key.getProject() == null) {
key = key.withProject(OpsContext.get().getPlatformLayerClient().getProject());
}
return key;
}
use of org.platformlayer.ids.ItemType in project platformlayer by platformlayer.
the class ManagedItemResource method checkItemKey.
private void checkItemKey(ItemBase item) throws OpsException {
PlatformLayerKey key = item.getKey();
ManagedItemId itemId = getItemId();
ServiceType serviceType = getServiceType();
ItemType itemType = getItemType();
ProjectId project = getProject();
if (key != null) {
if (key.getItemId() != null && !equal(key.getItemId(), itemId)) {
throw new OpsException("Item id mismatch");
}
if (key.getServiceType() != null && !equal(key.getServiceType(), serviceType)) {
throw new OpsException("Service type mismatch");
}
if (key.getItemType() != null && !key.getItemType().isEmpty() && !equal(key.getItemType(), itemType)) {
throw new OpsException("Item type mismatch");
}
if (key.getProject() != null && !equal(key.getProject(), project)) {
throw new OpsException("Project mismatch");
}
}
key = new PlatformLayerKey(null, project, serviceType, itemType, itemId);
item.setKey(key);
}
use of org.platformlayer.ids.ItemType in project platformlayer by platformlayer.
the class ServiceResource method getManagedCollectionResource.
@Path("{itemType}")
public XaasResourceBase getManagedCollectionResource(@PathParam("itemType") String itemType) {
getScope().put(new ItemType(itemType));
XaasResourceBase resources = objectInjector.getInstance(ManagedItemCollectionResource.class);
return resources;
}
Aggregations