@Override public boolean apply(OEntity input) { Object pv = input.getProperty(propName).getValue(); return (value == null) ? pv == null : value.equals(pv); } };
public OModifyRequest<OEntity> mergeEntity(OEntity entity) { return mergeEntity(entity.getEntitySet().getName(), entity.getEntityKey(), entity.getEntityTag()); }
protected static void reportEntity(String caption, OEntity entity) { report(caption); if (entity.getEntityTag() != null) report(" ETag: %s", entity.getEntityTag()); for (OProperty<?> p : entity.getProperties()) { Object v = p.getValue(); if (p.getType().equals(EdmSimpleType.BINARY) && v != null) v = org.odata4j.repack.org.apache.commons.codec.binary.Base64.encodeBase64String((byte[]) v).trim(); report(" %s: %s", p.getName(), v); } }
public void setOEntity(OEntity oEntity) { this.oEntity = oEntity; setEntitySetName(oEntity.getEntitySetName()); this.oEntityKey = oEntity != null ? oEntity.getEntityKey() : null; } }
public static String getEntityRelId(OEntity oe) { return getEntityRelId(oe.getEntitySet(), oe.getEntityKey()); }
public void writeRequestEntry(Writer w, Entry entry) { DateTime utc = new DateTime().withZone(DateTimeZone.UTC); String updated = InternalUtil.toString(utc); XMLWriter2 writer = XMLFactoryProvider2.getInstance().newXMLWriterFactory2().createXMLWriter(w); writer.startDocument(); writer.startElement(new QName2("entry"), atom); writer.writeNamespace("d", d); writer.writeNamespace("m", m); OEntity entity = entry.getEntity(); writeEntry(writer, null, entity.getProperties(), entity.getLinks(), null, updated, entity.getEntitySet(), false); writer.endDocument(); }
public static String create(List<OrderByExpression> orderByList, OEntity lastEntity) { // skip token = <orderbyvalue1,orderbyvalue2,>keystringwithoutparens List<String> values = new LinkedList<String>(); if (orderByList != null) { for (OrderByExpression orderBy : orderByList) { String orderByPropName = ((EntitySimpleProperty) orderBy.getExpression()).getPropertyName(); Object orderByPropValue = lastEntity.getProperty(orderByPropName).getValue(); String valueFilterString = Expression.asFilterString(Expression.literal(orderByPropValue)); values.add(valueFilterString); } } values.add(lastEntity.getEntityKey().toKeyStringWithoutParentheses()); return Enumerable.create(values).join(","); }
private void run(String[] args) { String uri = ODataEndpoints.NORTHWIND; ODataConsumer c = ODataConsumers.create("http://services.odata.org/validation/odatavalidator/"); Guid validationJobId = Guid.fromString("f4aa9495-ef40-469e-818c-29c4ec5fb2ed"); if (true) { OEntity newValidationJob = c.createEntity("ValidationJobs").properties(OProperties.string("Uri", uri), OProperties.string("Format", "atompub")).execute(); reportEntity("new job", newValidationJob); validationJobId = (Guid) newValidationJob.getEntityKey().asSingleValue(); } boolean complete = false; OEntity validationJob = null; while (!complete) { if (validationJob != null) InternalUtil.sleep(500); validationJob = c.getEntity("ValidationJobs", validationJobId).execute(); complete = validationJob.getProperty("Complete", Boolean.class).getValue(); } reportEntity("job", validationJob); for (OEntity testResult : c.getEntities(validationJob.getLink("TestResults", ORelatedEntitiesLink.class)).execute()) { reportEntity("result", testResult); } report("PayloadLines:"); for (OEntity payloadLine : c.getEntities(validationJob.getLink("PayloadLines", ORelatedEntitiesLink.class)).orderBy("LineNumber").execute()) report(payloadLine.getProperty("LineText", String.class).getValue()); }
public OEntityDeleteRequest deleteEntity(OEntity entity) { return new ConsumerDeleteEntityRequest(getClient(), getServiceRootUri(), getMetadata(), entity.getEntitySetName(), entity.getEntityKey(), entity.getEntityTag()); }
@Override public boolean execute(JPAContext context) { EntityManager em = context.getEntityManager(); EntityType<?> jpaEntityType = context.getEntity() .getJPAEntityType(); Object jpaEntity = context.getEntity().getJpaEntity(); OEntity entity = context.getEntity().getOEntity(); JPAProducer.applyOProperties(em, jpaEntityType, entity.getProperties(), jpaEntity); JPAProducer.applyOLinks(em, jpaEntityType, entity.getLinks(), jpaEntity); return false; } }
private void run(String[] args) { ODataConsumer c = ODataConsumers.create(ODataEndpoints.NETFLIX); // locate the netflix id for Morgan Spurlock int morganSpurlockId = c.getEntities("People").filter("substringof('Spurlock',Name)").execute().first().getProperty("Id", Integer.class).getValue(); // lookup and print all titles he's acted in List<OEntity> titlesActedIn = c.getEntities("People").nav(morganSpurlockId, "TitlesActedIn").execute().toList(); for (OEntity title : titlesActedIn) { for (OProperty<?> p : title.getProperties()) { report("%s: %s", p.getName(), p.getValue()); } report("\n"); } report("count: " + titlesActedIn.size()); }
@Override protected void writeContent(UriInfo uriInfo, JsonWriter jw, Entry target) { writeOEntity(uriInfo, jw, target.getEntity(), target.getEntity().getEntitySet(), false); }
private void run(String[] args) { ODataConsumer c = ODataConsumers.create(ODataEndpoints.EBAY); OEntity firstDeal = c.getEntities("Deals").top(1).execute().first(); reportEntity(firstDeal.getProperty("Title").getValue().toString(), c.getEntity(firstDeal.getLink("Item", ORelatedEntityLink.class)) .execute()); }
@Override public boolean apply(OEntity input) { if (skipping[0]) { String inputKey = input.getEntityKey().toKeyString(); if (queryInfo.skipToken.equals(inputKey)) skipping[0] = false; return true; } return false; } });
protected void writeOEntity(UriInfo uriInfo, JsonWriter jw, OEntity oe, EdmEntitySet ees, boolean isResponse) { jw.startObject(); { String baseUri = null; // TODO: I'm keeping this pattern of writing the __metadata if we have a non-null type..it seems like we could still // write the uri even if we don't have a type. Also, are there any scenarios where the entity type would be null? Not sure. if (isResponse && oe.getEntityType() != null) { baseUri = uriInfo.getBaseUri().toString(); jw.writeName("__metadata"); jw.startObject(); { String absId = baseUri + InternalUtil.getEntityRelId(oe); jw.writeName("uri"); jw.writeString(absId); jw.writeSeparator(); jw.writeName("type"); jw.writeString(oe.getEntityType().getFullyQualifiedTypeName()); } jw.endObject(); jw.writeSeparator(); } writeOProperties(jw, oe.getProperties()); writeLinks(jw, oe, uriInfo, isResponse); } jw.endObject(); }
public SqlStatement generate(JdbcMetadataMapping mapping, EdmEntitySet entitySet, OEntity entity) { JdbcTable table = mapping.getMappedTable(entitySet); StringBuilder sql = new StringBuilder("INSERT INTO " + table.tableName + "("); StringBuilder columns = new StringBuilder(); StringBuilder values = new StringBuilder(); List<SqlParameter> params = new ArrayList<SqlParameter>(); for (OProperty<?> prop : entity.getProperties()) { if (columns.length() > 0) columns.append(", "); if (values.length() > 0) values.append(", "); EdmProperty edmProp = entitySet.getType().findProperty(prop.getName()); JdbcColumn column = mapping.getMappedColumn(edmProp); columns.append(column.columnName); values.append("?"); params.add(new SqlParameter(prop.getValue(), null)); } sql.append(columns); sql.append(") VALUES ("); sql.append(values); sql.append(")"); return new SqlStatement(sql.toString(), ImmutableList.copyOf(params)); }
"term", oe == null ? ees.getType().getFullyQualifiedTypeName() : oe.getEntityType().getFullyQualifiedTypeName(), "scheme", scheme); OAtomStreamEntity stream = oe.findExtension(OAtomStreamEntity.class); if (stream != null) { hasStream = true;
private static Iterable<OEntity> listChildren(ODataConsumer c, OEntity parent, String child) { return c.getEntities(parent.getLink(child, ORelatedEntitiesLink.class)).execute().take(MAX_LISTING); }
private OAtomEntity getAtomInfo(OEntity oe) { if (oe != null) { OAtomEntity atomEntity = oe.findExtension(OAtomEntity.class); if (atomEntity != null) return atomEntity; } return new OAtomEntity() { @Override public String getAtomEntityTitle() { return null; } @Override public String getAtomEntitySummary() { return null; } @Override public String getAtomEntityAuthor() { return null; } @Override public LocalDateTime getAtomEntityUpdated() { return null; } }; }