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();
}
}
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;
}
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;
}
Aggregations