use of org.apache.olingo.odata2.api.edm.Edm in project camel by apache.
the class Olingo2AppAPITest method testReadFeed.
@Test
public void testReadFeed() throws Exception {
final TestOlingo2ResponseHandler<ODataFeed> responseHandler = new TestOlingo2ResponseHandler<ODataFeed>();
olingoApp.read(edm, MANUFACTURERS, null, responseHandler);
final ODataFeed dataFeed = responseHandler.await();
assertNotNull("Data feed", dataFeed);
LOG.info("Entries: {}", prettyPrint(dataFeed));
}
use of org.apache.olingo.odata2.api.edm.Edm in project camel by apache.
the class Olingo2AppAPITest method testCreateUpdateDeleteEntry.
@Test
public void testCreateUpdateDeleteEntry() throws Exception {
// create entry to update
final TestOlingo2ResponseHandler<ODataEntry> entryHandler = new TestOlingo2ResponseHandler<ODataEntry>();
olingoApp.create(edm, MANUFACTURERS, getEntityData(), entryHandler);
ODataEntry createdEntry = entryHandler.await();
LOG.info("Created Entry: {}", prettyPrint(createdEntry));
Map<String, Object> data = getEntityData();
@SuppressWarnings("unchecked") Map<String, Object> address = (Map<String, Object>) data.get(ADDRESS);
data.put("Name", "MyCarManufacturer Renamed");
address.put("Street", "Main Street");
final TestOlingo2ResponseHandler<HttpStatusCodes> statusHandler = new TestOlingo2ResponseHandler<HttpStatusCodes>();
olingoApp.update(edm, TEST_CREATE_MANUFACTURER, data, statusHandler);
statusHandler.await();
statusHandler.reset();
data.put("Name", "MyCarManufacturer Patched");
olingoApp.patch(edm, TEST_CREATE_MANUFACTURER, data, statusHandler);
statusHandler.await();
entryHandler.reset();
olingoApp.read(edm, TEST_CREATE_MANUFACTURER, null, entryHandler);
ODataEntry updatedEntry = entryHandler.await();
LOG.info("Updated Entry successfully: {}", prettyPrint(updatedEntry));
statusHandler.reset();
olingoApp.delete(TEST_CREATE_MANUFACTURER, statusHandler);
HttpStatusCodes statusCode = statusHandler.await();
LOG.info("Deletion of Entry was successful: {}: {}", statusCode.getStatusCode(), statusCode.getInfo());
try {
LOG.info("Verify Delete Entry");
entryHandler.reset();
olingoApp.read(edm, TEST_CREATE_MANUFACTURER, null, entryHandler);
entryHandler.await();
fail("Entry not deleted!");
} catch (Exception e) {
LOG.info("Deleted entry not found: {}", e.getMessage());
}
}
use of org.apache.olingo.odata2.api.edm.Edm in project camel by apache.
the class Olingo2AppAPITest method testReadUnparsedEntry.
@Test
public void testReadUnparsedEntry() throws Exception {
final TestOlingo2ResponseHandler<InputStream> responseHandler = new TestOlingo2ResponseHandler<InputStream>();
olingoApp.uread(edm, TEST_MANUFACTURER, null, responseHandler);
InputStream rawentry = responseHandler.await();
ODataEntry entry = EntityProvider.readEntry(TEST_FORMAT_STRING, edmEntitySetMap.get(MANUFACTURERS), rawentry, EntityProviderReadProperties.init().build());
LOG.info("Single Entry: {}", prettyPrint(entry));
responseHandler.reset();
olingoApp.uread(edm, TEST_CAR, null, responseHandler);
rawentry = responseHandler.await();
entry = EntityProvider.readEntry(TEST_FORMAT_STRING, edmEntitySetMap.get(CARS), rawentry, EntityProviderReadProperties.init().build());
LOG.info("Single Entry: {}", prettyPrint(entry));
responseHandler.reset();
final Map<String, String> queryParams = new HashMap<String, String>();
queryParams.put(SystemQueryOption.$expand.toString(), CARS);
olingoApp.uread(edm, TEST_MANUFACTURER, queryParams, responseHandler);
rawentry = responseHandler.await();
ODataEntry entryExpanded = EntityProvider.readEntry(TEST_FORMAT_STRING, edmEntitySetMap.get(MANUFACTURERS), rawentry, EntityProviderReadProperties.init().build());
LOG.info("Single Entry with expanded Cars relation: {}", prettyPrint(entryExpanded));
}
use of org.apache.olingo.odata2.api.edm.Edm in project camel by apache.
the class Olingo2AppImpl method replaceContentId.
private static String replaceContentId(Edm edm, String entityReference, Map<String, String> contentIdMap) throws EdmException {
final int pathSeparator = entityReference.indexOf('/');
final StringBuilder referencedEntity;
if (pathSeparator == -1) {
referencedEntity = new StringBuilder(contentIdMap.get(entityReference));
} else {
referencedEntity = new StringBuilder(contentIdMap.get(entityReference.substring(0, pathSeparator)));
}
// create a dummy entity location by adding a dummy key predicate
// look for a Container name if available
String referencedEntityName = referencedEntity.toString();
final int containerSeparator = referencedEntityName.lastIndexOf('.');
final EdmEntityContainer entityContainer;
if (containerSeparator != -1) {
final String containerName = referencedEntityName.substring(0, containerSeparator);
referencedEntityName = referencedEntityName.substring(containerSeparator + 1);
entityContainer = edm.getEntityContainer(containerName);
if (entityContainer == null) {
throw new IllegalArgumentException("EDM does not have entity container " + containerName);
}
} else {
entityContainer = edm.getDefaultEntityContainer();
if (entityContainer == null) {
throw new IllegalArgumentException("EDM does not have a default entity container" + ", use a fully qualified entity set name");
}
}
final EdmEntitySet entitySet = entityContainer.getEntitySet(referencedEntityName);
final List<EdmProperty> keyProperties = entitySet.getEntityType().getKeyProperties();
if (keyProperties.size() == 1) {
referencedEntity.append("('dummy')");
} else {
referencedEntity.append("(");
for (EdmProperty keyProperty : keyProperties) {
referencedEntity.append(keyProperty.getName()).append('=').append("'dummy',");
}
referencedEntity.deleteCharAt(referencedEntity.length() - 1);
referencedEntity.append(')');
}
return pathSeparator == -1 ? referencedEntityName : referencedEntity.append(entityReference.substring(pathSeparator)).toString();
}
use of org.apache.olingo.odata2.api.edm.Edm in project camel by apache.
the class Olingo2AppWrapper method getEdm.
// double checked locking based singleton Edm reader
public Edm getEdm() throws RuntimeCamelException {
Edm localEdm = edm;
if (localEdm == null) {
synchronized (this) {
localEdm = edm;
if (localEdm == null) {
final CountDownLatch latch = new CountDownLatch(1);
final Exception[] error = new Exception[1];
olingo2App.read(null, "$metadata", null, new Olingo2ResponseHandler<Edm>() {
@Override
public void onResponse(Edm response) {
edm = response;
latch.countDown();
}
@Override
public void onException(Exception ex) {
error[0] = ex;
latch.countDown();
}
@Override
public void onCanceled() {
error[0] = new RuntimeCamelException("OData HTTP request cancelled!");
latch.countDown();
}
});
try {
// wait until response or timeout
latch.await();
final Exception ex = error[0];
if (ex != null) {
if (ex instanceof RuntimeCamelException) {
throw (RuntimeCamelException) ex;
} else {
final String message = ex.getMessage() != null ? ex.getMessage() : ex.getClass().getName();
throw new RuntimeCamelException("Error reading EDM: " + message, ex);
}
}
} catch (InterruptedException e) {
throw new RuntimeCamelException(e.getMessage(), e);
}
localEdm = edm;
}
}
}
return localEdm;
}
Aggregations