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