Search in sources :

Example 11 with ManagedItemId

use of org.platformlayer.ids.ManagedItemId 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 12 with ManagedItemId

use of org.platformlayer.ids.ManagedItemId in project platformlayer by platformlayer.

the class ItemServiceImpl method findItem.

@Override
public <T extends ItemBase> T findItem(ProjectAuthorization auth, Class<T> itemClass, String id) throws OpsException {
    ModelClass<T> modelClass = serviceProviderDirectory.getModelClass(itemClass);
    // Class<T> javaClass = modelClass.getJavaClass();
    ProjectId project = getProjectId(auth);
    PlatformLayerKey modelKey = new PlatformLayerKey(null, project, modelClass.getServiceType(), modelClass.getItemType(), new ManagedItemId(id));
    boolean fetchTags = true;
    T managedItem;
    try {
        managedItem = Casts.checkedCast(repository.getManagedItem(modelKey, fetchTags, SecretProvider.from(auth)), itemClass);
    } catch (RepositoryException e) {
        throw new OpsException("Error fetching item from database", e);
    }
    return managedItem;
}
Also used : OpsException(org.platformlayer.ops.OpsException) ProjectId(org.platformlayer.ids.ProjectId) PlatformLayerKey(org.platformlayer.core.model.PlatformLayerKey) RepositoryException(org.platformlayer.RepositoryException) ManagedItemId(org.platformlayer.ids.ManagedItemId)

Example 13 with ManagedItemId

use of org.platformlayer.ids.ManagedItemId in project platformlayer by platformlayer.

the class JdbcManagedItemRepository method updateManagedItem.

@Override
@JdbcTransaction
public <T extends ItemBase> T updateManagedItem(ProjectId project, T item) throws RepositoryException {
    Class<T> itemClass = (Class<T>) item.getClass();
    DbHelper db = new DbHelper(itemClass, project);
    try {
        ManagedItemId itemId = new ManagedItemId(item.getId());
        ModelClass<T> modelClass = serviceProviderDirectory.getModelClass(itemClass);
        int projectId = db.mapToValue(project);
        int modelId = db.mapToValue(modelClass.getItemType());
        int serviceId = db.mapToValue(modelClass.getServiceType());
        ItemEntity rs = db.queries.findItem(serviceId, modelId, projectId, itemId.getKey());
        if (rs == null) {
            throw new RepositoryException("Item not found");
        }
        byte[] secretData = rs.secret;
        CryptoKey itemSecret;
        if (secretData == null) {
            itemSecret = FathomdbCrypto.generateKey();
            secretData = itemSecrets.encodeItemSecret(itemSecret);
            db.updateSecret(itemId, secretData);
        } else {
            itemSecret = item.secret.getSecret();
        }
        byte[] data = serialize(item, itemSecret);
        db.updateItem(itemId, data, item.state);
        // Note: we can't change tags here (that needs a separate call to updateTags)
        SecretProvider secretProvider = SecretProvider.forKey(itemSecret);
        boolean fetchTags = true;
        return fetchItem(db, modelClass.getServiceType(), modelClass.getItemType(), project, itemId, itemClass, secretProvider, fetchTags);
    } catch (SQLException e) {
        throw new RepositoryException("Error running query", e);
    } finally {
        db.close();
    }
}
Also used : SQLException(java.sql.SQLException) CryptoKey(com.fathomdb.crypto.CryptoKey) AesCryptoKey(com.fathomdb.crypto.AesCryptoKey) RepositoryException(org.platformlayer.RepositoryException) ManagedItemId(org.platformlayer.ids.ManagedItemId) ModelClass(org.platformlayer.xaas.services.ModelClass) SecretProvider(org.platformlayer.auth.crypto.SecretProvider) JdbcTransaction(com.fathomdb.jdbc.JdbcTransaction)

Example 14 with ManagedItemId

use of org.platformlayer.ids.ManagedItemId in project platformlayer by platformlayer.

the class ManagedItemCollectionResource method retrieveSingleService.

@Path("{id}")
@Produces({ XML, JSON })
public ManagedItemResource retrieveSingleService(@PathParam("id") String id) {
    ManagedItemId itemId = new ManagedItemId(id);
    getScope().put(itemId);
    ManagedItemResource resource = objectInjector.getInstance(ManagedItemResource.class);
    return resource;
}
Also used : ManagedItemId(org.platformlayer.ids.ManagedItemId) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces)

Example 15 with ManagedItemId

use of org.platformlayer.ids.ManagedItemId in project platformlayer by platformlayer.

the class FederatedPlatformLayerClient method mapToChild.

private MappedPlatformLayerKey mapToChild(PlatformLayerKey plk) {
    // if (plk.getHost() != null) {
    // 
    // }
    ManagedItemId itemId = plk.getItemId();
    if (itemId == null || itemId.isEmpty()) {
        throw new IllegalArgumentException();
    }
    FederationKey host = plk.getHost();
    if (host == null) {
        host = FederationKey.LOCAL;
    }
    ProjectId project = plk.getProject();
    if (project == null) {
        project = defaultProject;
    // project = federationMap.getLocalClient().getProject();
    }
    ChildClient childClient = getClient(new FederationMapping(host, project));
    MappedPlatformLayerKey mapped = new MappedPlatformLayerKey();
    mapped.child = childClient;
    mapped.key = new PlatformLayerKey(host, project, plk.getServiceType(), plk.getItemType(), plk.getItemId());
    return mapped;
// Iterable<ChildClient> childClients = getChildClients(plk);
// ChildClient client = null;
// for (ChildClient childClient : childClients) {
// if (client == null) {
// client = childClient;
// } else {
// throw new IllegalStateException("Multiple clients found");
// }
// }
// return client;
}
Also used : ProjectId(org.platformlayer.ids.ProjectId) PlatformLayerKey(org.platformlayer.core.model.PlatformLayerKey) ManagedItemId(org.platformlayer.ids.ManagedItemId) FederationKey(org.platformlayer.ids.FederationKey)

Aggregations

ManagedItemId (org.platformlayer.ids.ManagedItemId)20 PlatformLayerKey (org.platformlayer.core.model.PlatformLayerKey)13 ProjectId (org.platformlayer.ids.ProjectId)9 RepositoryException (org.platformlayer.RepositoryException)7 ItemType (org.platformlayer.ids.ItemType)5 ServiceType (org.platformlayer.ids.ServiceType)5 FederationKey (org.platformlayer.ids.FederationKey)4 JobData (org.platformlayer.jobs.model.JobData)4 OpsException (org.platformlayer.ops.OpsException)4 JdbcTransaction (com.fathomdb.jdbc.JdbcTransaction)3 SQLException (java.sql.SQLException)3 AesCryptoKey (com.fathomdb.crypto.AesCryptoKey)2 CryptoKey (com.fathomdb.crypto.CryptoKey)2 Path (javax.ws.rs.Path)2 SecretProvider (org.platformlayer.auth.crypto.SecretProvider)2 ModelClass (org.platformlayer.xaas.services.ModelClass)2 ServiceProvider (org.platformlayer.xaas.services.ServiceProvider)2 JaxbHelper (org.platformlayer.xml.JaxbHelper)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1