Search in sources :

Example 11 with ItemType

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;
}
Also used : ElementInfo(org.platformlayer.xml.XmlHelper.ElementInfo) ItemType(org.platformlayer.ids.ItemType)

Example 12 with ItemType

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);
}
Also used : ItemType(org.platformlayer.ids.ItemType) ProjectId(org.platformlayer.ids.ProjectId) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) ManagedItemId(org.platformlayer.ids.ManagedItemId) FederationKey(org.platformlayer.ids.FederationKey) ServiceType(org.platformlayer.ids.ServiceType)

Example 13 with ItemType

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;
}
Also used : ServiceType(org.platformlayer.ids.ServiceType) ItemType(org.platformlayer.ids.ItemType)

Example 14 with ItemType

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);
}
Also used : OpsException(org.platformlayer.ops.OpsException) ServiceType(org.platformlayer.ids.ServiceType) ItemType(org.platformlayer.ids.ItemType) ProjectId(org.platformlayer.ids.ProjectId) PlatformLayerKey(org.platformlayer.core.model.PlatformLayerKey) ManagedItemId(org.platformlayer.ids.ManagedItemId)

Example 15 with ItemType

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;
}
Also used : ItemType(org.platformlayer.ids.ItemType) Path(javax.ws.rs.Path)

Aggregations

ItemType (org.platformlayer.ids.ItemType)15 ServiceType (org.platformlayer.ids.ServiceType)10 ProjectId (org.platformlayer.ids.ProjectId)6 PlatformLayerKey (org.platformlayer.core.model.PlatformLayerKey)5 FederationKey (org.platformlayer.ids.FederationKey)5 ManagedItemId (org.platformlayer.ids.ManagedItemId)5 ServiceInfo (org.platformlayer.core.model.ServiceInfo)3 OpsException (org.platformlayer.ops.OpsException)2 ServiceProvider (org.platformlayer.xaas.services.ServiceProvider)2 JaxbHelper (org.platformlayer.xml.JaxbHelper)2 JdbcTransaction (com.fathomdb.jdbc.JdbcTransaction)1 Function (com.google.common.base.Function)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 SQLException (java.sql.SQLException)1 Map (java.util.Map)1 Path (javax.ws.rs.Path)1 RepositoryException (org.platformlayer.RepositoryException)1 HostPolicy (org.platformlayer.core.model.HostPolicy)1 Tag (org.platformlayer.core.model.Tag)1