Search in sources :

Example 6 with ModelClass

use of org.platformlayer.xaas.services.ModelClass 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 7 with ModelClass

use of org.platformlayer.xaas.services.ModelClass in project platformlayer by platformlayer.

the class ProviderHelper method listItemsProviding.

public <T> List<ProviderOf<T>> listItemsProviding(Class<T> serviceClass) throws OpsException {
    List<ProviderOf<T>> providers = Lists.newArrayList();
    List<ModelClass<?>> models = findModelsProviding(serviceClass);
    for (ModelClass<? extends ItemBase> model : models) {
        for (ItemBase item : platformLayer.listItems(model.getJavaClass())) {
            providers.add(new ProviderOf<T>(model, item));
        }
    }
    return providers;
}
Also used : ModelClass(org.platformlayer.xaas.services.ModelClass) ItemBase(org.platformlayer.core.model.ItemBase)

Example 8 with ModelClass

use of org.platformlayer.xaas.services.ModelClass in project platformlayer by platformlayer.

the class ServiceProviderHelpers method getModelSubclasses.

public <T extends ItemBase> List<ModelClass<? extends T>> getModelSubclasses(Class<T> parent) {
    List<ModelClass<? extends T>> modelClasses = Lists.newArrayList();
    for (ServiceInfo serviceInfo : serviceProviderDictionary.getAllServices()) {
        ServiceType serviceType = new ServiceType(serviceInfo.serviceType);
        ServiceProvider serviceProvider = serviceProviderDictionary.getServiceProvider(serviceType);
        for (ModelClass<?> modelClass : serviceProvider.getModels().all()) {
            Class<?> javaClass = modelClass.getJavaClass();
            if (parent.isAssignableFrom(javaClass)) {
                modelClasses.add((ModelClass<? extends T>) modelClass);
            }
        }
    }
    return modelClasses;
}
Also used : ServiceInfo(org.platformlayer.core.model.ServiceInfo) ModelClass(org.platformlayer.xaas.services.ModelClass) ServiceType(org.platformlayer.ids.ServiceType) ServiceProvider(org.platformlayer.xaas.services.ServiceProvider)

Aggregations

ModelClass (org.platformlayer.xaas.services.ModelClass)8 ServiceProvider (org.platformlayer.xaas.services.ServiceProvider)5 ItemBase (org.platformlayer.core.model.ItemBase)3 ServiceInfo (org.platformlayer.core.model.ServiceInfo)3 ServiceType (org.platformlayer.ids.ServiceType)3 RepositoryException (org.platformlayer.RepositoryException)2 SecretProvider (org.platformlayer.auth.crypto.SecretProvider)2 ManagedItemId (org.platformlayer.ids.ManagedItemId)2 AesCryptoKey (com.fathomdb.crypto.AesCryptoKey)1 CryptoKey (com.fathomdb.crypto.CryptoKey)1 JdbcTransaction (com.fathomdb.jdbc.JdbcTransaction)1 StringWriter (java.io.StringWriter)1 SQLException (java.sql.SQLException)1 List (java.util.List)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 JAXBContext (javax.xml.bind.JAXBContext)1 JAXBException (javax.xml.bind.JAXBException)1 Filter (org.platformlayer.Filter)1