Java Code Examples for org.apache.olingo.odata2.api.edm.EdmEntitySet#getName()

The following examples show how to use org.apache.olingo.odata2.api.edm.EdmEntitySet#getName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: User.java    From DataHubSystem with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public void createLink(UriInfo link) throws ODataException
{
   EdmEntitySet target_es = link.getTargetEntitySet();
   if (!target_es.getName().equals(Model.PRODUCT.getName()))
   {
      throw new ODataException("Cannot create link from Users to " + target_es.getName());
   }

   String pdt_uuid_s = link.getTargetKeyPredicates().get(0).getLiteral();
   fr.gael.dhus.database.object.Product pta = PRODUCT_SERVICE.getProduct(pdt_uuid_s);
   if (pta == null)
   {
      throw new InvalidKeyException(pdt_uuid_s, this.getClass().getSimpleName());
   }

   PRODUCTCART_SERVICE.addProductToCart(this.user.getUUID(), pta.getId());
}
 
Example 2
Source File: User.java    From DataHubSystem with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public void deleteLink(DeleteUriInfo link) throws ODataException
{
   EdmEntitySet target_es = link.getTargetEntitySet();
   if (!target_es.getName().equals(Model.PRODUCT.getName()))
   {
      throw new ODataException("Cannot create link from Users to " + target_es.getName());
   }

   String pdt_uuid_s = link.getTargetKeyPredicates().get(0).getLiteral();
   fr.gael.dhus.database.object.Product pta = PRODUCT_SERVICE.getProduct(pdt_uuid_s);
   if (pta == null)
   {
      throw new InvalidKeyException(pdt_uuid_s, this.getClass().getSimpleName());
   }

   PRODUCTCART_SERVICE.removeProductFromCart(this.user.getUUID(), pta.getId());
}
 
Example 3
Source File: AnnotationInMemoryDs.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Override
public void writeBinaryData(final EdmEntitySet entitySet, final Object mediaEntityInstance,
    final BinaryData binaryData)
    throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException {

  try {
    DataStore<Object> dataStore = getDataStore(entitySet);
    Object readEntry = dataStore.read(mediaEntityInstance);
    if (readEntry == null) {
      throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
    } else {
      ANNOTATION_HELPER.setValueForAnnotatedField(
          mediaEntityInstance, EdmMediaResourceContent.class, binaryData.getData());
      ANNOTATION_HELPER.setValueForAnnotatedField(
          mediaEntityInstance, EdmMediaResourceMimeType.class, binaryData.getMimeType());
    }
  } catch (ODataAnnotationException e) {
    throw new AnnotationRuntimeException("Invalid media resource annotation at entity set '" + entitySet.getName()
        + "' with message '" + e.getMessage() + "'.", e);
  }
}
 
Example 4
Source File: EdmEntityContainerImpl.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Override
public EdmAssociationSet getAssociationSet(final EdmEntitySet sourceEntitySet,
    final EdmNavigationProperty navigationProperty) throws EdmException {
  EdmAssociation edmAssociation = navigationProperty.getRelationship();
  String association = edmAssociation.getNamespace() + "." + edmAssociation.getName();
  String entitySetName = sourceEntitySet.getName();
  String entitySetFromRole = navigationProperty.getFromRole();

  String key = entitySetName + ">>" + association + ">>" + entitySetFromRole;

  for (Entry<String, EdmAssociationSet> edmAssociationSet : edmAssociationSetMap.entrySet()) {
    if (edmAssociationSet.getKey().equalsIgnoreCase(key)) {
      return edmAssociationSet.getValue();
    }
  }
 return null;

}
 
Example 5
Source File: AnnotationInMemoryDs.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Override
public Object newDataObject(final EdmEntitySet entitySet)
    throws ODataNotImplementedException, EdmException, ODataApplicationException {

  DataStore<Object> dataStore = getDataStore(entitySet);
  if (dataStore != null) {
    return dataStore.createInstance();
  }

  throw new AnnotationRuntimeException("No DataStore found for entitySet with name: " + entitySet.getName());
}
 
Example 6
Source File: JPAExpandCallBack.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private List<EdmProperty> getEdmProperties(final EdmEntitySet entitySet, final ExpandSelectTreeNode expandTreeNode)
    throws ODataApplicationException {

  try {
    String name = entitySet.getName();
    if (edmPropertyMap.containsKey(name)) {
      return edmPropertyMap.get(name);
    }
    List<EdmProperty> edmProperties = new ArrayList<EdmProperty>();
    edmProperties.addAll(expandTreeNode.getProperties());
    boolean hit = false;
    for (EdmProperty keyProperty : entitySet.getEntityType().getKeyProperties()) {
      hit = false;
      for (EdmProperty property : edmProperties) {
        if (property.getName().equals(keyProperty.getName())) {
          hit = true;
          break;
        }
      }
      if (hit == false) {
        edmProperties.add(keyProperty);
      }
    }
    edmPropertyMap.put(name, edmProperties);
    return edmProperties;
  } catch (EdmException e) {
    throw new ODataApplicationException(e.getMessage(), Locale.getDefault(), e);
  }
}
 
Example 7
Source File: EdmEntityContainerImplProv.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Override
public EdmAssociationSet getAssociationSet(final EdmEntitySet sourceEntitySet,
    final EdmNavigationProperty navigationProperty) throws EdmException {
  EdmAssociation edmAssociation = navigationProperty.getRelationship();
  String association = edmAssociation.getNamespace() + "." + edmAssociation.getName();
  String entitySetName = sourceEntitySet.getName();
  String entitySetFromRole = navigationProperty.getFromRole();

  String key = entitySetName + ">>" + association + ">>" + entitySetFromRole;

  EdmAssociationSet edmAssociationSet = edmAssociationSets.get(key);
  if (edmAssociationSet != null) {
    return edmAssociationSet;
  }

  AssociationSet associationSet;
  FullQualifiedName associationFQName =
      new FullQualifiedName(edmAssociation.getNamespace(), edmAssociation.getName());
  try {
    associationSet =
        edm.edmProvider.getAssociationSet(entityContainerInfo.getName(), associationFQName, entitySetName,
            entitySetFromRole);
  } catch (ODataException e) {
    throw new EdmException(EdmException.PROVIDERPROBLEM, e);
  }

  if (associationSet != null) {
    edmAssociationSet = createAssociationSet(associationSet);
    edmAssociationSets.put(key, edmAssociationSet);
    return edmAssociationSet;
  } else if (edmExtendedEntityContainer != null) {
    edmAssociationSet = edmExtendedEntityContainer.getAssociationSet(sourceEntitySet, navigationProperty);
    edmAssociationSets.put(key, edmAssociationSet);
    return edmAssociationSet;
  } else {
    throw new EdmException(EdmException.COMMON);
  }
}
 
Example 8
Source File: EdmEntityContainerImplProvTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetEntitySets() throws EdmException {

  List<EdmEntitySet> entitySets = edmEntityContainer.getEntitySets();
  assertNotNull(entitySets);
  assertEquals(3, entitySets.size());

  for (EdmEntitySet entitySet : entitySets) {
    String name = entitySet.getName();
    boolean expectedName = "fooFromParent".equals(name)
        || "foo".equals(name)
        || "bar".equals(name);
    assertTrue("Found not expected name: " + name, expectedName);
  }
}
 
Example 9
Source File: AnnotationInMemoryDs.java    From olingo-odata2 with Apache License 2.0 3 votes vote down vote up
/**
 * Returns corresponding DataStore for EdmEntitySet or if no data store is registered an
 * AnnotationRuntimeException is thrown.
 * Never returns NULL.
 * 
 * @param entitySet for which the corresponding DataStore is returned
 * @return a DataStore object
 * @throws EdmException
 * @throws AnnotationRuntimeException if no DataStore is found
 */
private DataStore<Object> getDataStore(final EdmEntitySet entitySet) throws EdmException {
  final String name = entitySet.getName();
  DataStore<Object> dataStore = dataStores.get(name);
  if (dataStore == null) {
    throw new AnnotationRuntimeException("No DataStore found for entity set '" + entitySet + "'.");
  }
  return dataStore;
}