Package org.apache.olingo.odata2.api.exception

Examples of org.apache.olingo.odata2.api.exception.ODataNotFoundException


      } else if (ENTITY_SET_NAME_MANUFACTURERS.equals(entitySet.getName())) {
        return EntityProvider.writeFeed(contentType, entitySet, dataStore.getManufacturers(),
            EntityProviderWriteProperties.serviceRoot(getContext().getPathInfo().getServiceRoot()).build());
      }

      throw new ODataNotFoundException(ODataNotFoundException.ENTITY);

    } else if (uriInfo.getNavigationSegments().size() == 1) {
      // navigation first level, simplified example for illustration purposes only
      entitySet = uriInfo.getTargetEntitySet();

      if (ENTITY_SET_NAME_CARS.equals(entitySet.getName())) {
        int manufacturerKey = getKeyValue(uriInfo.getKeyPredicates().get(0));

        List<Map<String, Object>> cars = new ArrayList<Map<String, Object>>();
        cars.addAll(dataStore.getCarsFor(manufacturerKey));

        return EntityProvider.writeFeed(contentType, entitySet, cars, EntityProviderWriteProperties.serviceRoot(
            getContext().getPathInfo().getServiceRoot()).build());
      }

      throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
    }

    throw new ODataNotImplementedException();
  }
View Full Code Here


          return EntityProvider.writeEntry(contentType, entitySet, data, propertiesBuilder.build());
        }
      }

      throw new ODataNotFoundException(ODataNotFoundException.ENTITY);

    } else if (uriInfo.getNavigationSegments().size() == 1) {
      // navigation first level, simplified example for illustration purposes only
      EdmEntitySet entitySet = uriInfo.getTargetEntitySet();

      Map<String, Object> data = null;

      if (ENTITY_SET_NAME_MANUFACTURERS.equals(entitySet.getName())) {
        int carKey = getKeyValue(uriInfo.getKeyPredicates().get(0));
        data = dataStore.getManufacturerFor(carKey);
      }

      if (data != null) {
        return EntityProvider.writeEntry(contentType, uriInfo.getTargetEntitySet(),
            data, EntityProviderWriteProperties.serviceRoot(getContext().getPathInfo().getServiceRoot()).build());
      }

      throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
    }

    throw new ODataNotImplementedException();
  }
View Full Code Here

    final String mappedKeyName =
        (String) uriInfo.getTargetEntitySet().getEntityType().getKeyProperties().get(0).getMapping().getObject();
    final String keyValue = uriInfo.getKeyPredicates().get(0).getLiteral();
    final int index = indexOf(mappedKeyName, keyValue);
    if ((index < 0) || (index > records.size())) {
      throw new ODataNotFoundException(ODataNotFoundException.ENTITY.addContent(keyValue));
    }
    final HashMap<String, String> record = records.get(index);

    final HashMap<String, Object> data = new HashMap<String, Object>();
    for (final String pName : uriInfo.getTargetEntitySet().getEntityType().getPropertyNames()) {
View Full Code Here

        (String) uriInfo.getTargetEntitySet().getEntityType().getKeyProperties().get(0).getMapping().getObject();
    final String keyValue = uriInfo.getKeyPredicates().get(0).getLiteral();

    final int index = indexOf(mappedKeyName, keyValue);
    if ((index < 0) || (index > records.size())) {
      throw new ODataNotFoundException(ODataNotFoundException.ENTITY.addContent(keyValue));
    }
    final HashMap<String, String> record = records.get(index);

    final String mappedPropertyName = (String) property.getMapping().getObject();
    final Object value = record.get(mappedPropertyName);
View Full Code Here

    for (final String method : methodName.split("\\.", -1)) {
      if (dataObject != null) {
        try {
          dataObject = dataObject.getClass().getMethod(method).invoke(dataObject);
        } catch (SecurityException e) {
          throw new ODataNotFoundException(ODataHttpException.COMMON, e);
        } catch (NoSuchMethodException e) {
          throw new ODataNotFoundException(ODataHttpException.COMMON, e);
        } catch (IllegalArgumentException e) {
          throw new ODataNotFoundException(ODataHttpException.COMMON, e);
        } catch (IllegalAccessException e) {
          throw new ODataNotFoundException(ODataHttpException.COMMON, e);
        } catch (InvocationTargetException e) {
          throw new ODataNotFoundException(ODataHttpException.COMMON, e);
        }
      }
    }

    return dataObject;
View Full Code Here

          }
          break;
        }
      }
      if (!found) {
        throw new ODataNotFoundException(null);
      }
    } catch (SecurityException e) {
      throw new ODataNotFoundException(null, e);
    } catch (IllegalArgumentException e) {
      throw new ODataNotFoundException(null, e);
    } catch (IllegalAccessException e) {
      throw new ODataNotFoundException(null, e);
    } catch (InvocationTargetException e) {
      throw new ODataNotFoundException(null, e);
    }
  }
View Full Code Here

    }
  }

  private <T> Class<?> getType(final T data, final String methodName) throws ODataNotFoundException {
    if (data == null) {
      throw new ODataNotFoundException(ODataHttpException.COMMON);
    }

    Class<?> type = data.getClass();
    for (final String method : methodName.split("\\.", -1)) {
      try {
        type = type.getMethod(method).getReturnType();
        if (type.isPrimitive()) {
          if (type == boolean.class) {
            type = Boolean.class;
          } else if (type == byte.class) {
            type = Byte.class;
          } else if (type == short.class) {
            type = Short.class;
          } else if (type == int.class) {
            type = Integer.class;
          } else if (type == long.class) {
            type = Long.class;
          } else if (type == float.class) {
            type = Float.class;
          } else if (type == double.class) {
            type = Double.class;
          }
        }
      } catch (final SecurityException e) {
        throw new ODataNotFoundException(ODataHttpException.COMMON, e);
      } catch (final NoSuchMethodException e) {
        throw new ODataNotFoundException(ODataHttpException.COMMON, e);
      }
    }
    return type;
  }
View Full Code Here

      for (final Employee employee : dataContainer.getEmployees()) {
        if (employee.getId().equals(keys.get("EmployeeId"))) {
          return employee;
        }
      }
      throw new ODataNotFoundException(ODataNotFoundException.ENTITY);

    } else if (ENTITYSET_1_2.equals(entitySet.getName())) {
      for (final Team team : dataContainer.getTeams()) {
        if (team.getId().equals(keys.get("Id"))) {
          return team;
        }
      }
      throw new ODataNotFoundException(ODataNotFoundException.ENTITY);

    } else if (ENTITYSET_1_3.equals(entitySet.getName())) {
      for (final Room room : dataContainer.getRooms()) {
        if (room.getId().equals(keys.get("Id"))) {
          return room;
        }
      }
      throw new ODataNotFoundException(ODataNotFoundException.ENTITY);

    } else if (ENTITYSET_1_4.equals(entitySet.getName())) {
      for (final Manager manager : dataContainer.getManagers()) {
        if (manager.getId().equals(keys.get("EmployeeId"))) {
          return manager;
        }
      }
      throw new ODataNotFoundException(ODataNotFoundException.ENTITY);

    } else if (ENTITYSET_1_5.equals(entitySet.getName())) {
      for (final Building building : dataContainer.getBuildings()) {
        if (building.getId().equals(keys.get("Id"))) {
          return building;
        }
      }
      throw new ODataNotFoundException(ODataNotFoundException.ENTITY);

    } else if (ENTITYSET_2_1.equals(entitySet.getName())) {
      for (final Photo photo : dataContainer.getPhotos()) {
        if (photo.getId() == (Integer) keys.get("Id")
            && photo.getType().equals(keys.get("Type"))) {
          return photo;
        }
      }
      throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
    }

    throw new ODataNotImplementedException();
  }
View Full Code Here

      } else if (ENTITYSET_1_4.equals(sourceEntitySet.getName())) {
        data = ((Manager) sourceData).getEmployees();
      }

      if (data.isEmpty()) {
        throw new ODataNotFoundException(null);
      }
      if (targetKeys.isEmpty()) {
        return Arrays.asList(data.toArray());
      } else {
        for (final Object employee : data) {
          if (((Employee) employee).getId().equals(targetKeys.get("EmployeeId"))) {
            return employee;
          }
        }
      }
      throw new ODataNotFoundException(ODataNotFoundException.ENTITY);

    } else if (ENTITYSET_1_2.equals(targetEntitySet.getName())) {
      if (((Employee) sourceData).getTeam() == null) {
        throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
      } else {
        return ((Employee) sourceData).getTeam();
      }

    } else if (ENTITYSET_1_3.equals(targetEntitySet.getName())) {
      if (ENTITYSET_1_1.equals(sourceEntitySet.getName())) {
        if (((Employee) sourceData).getRoom() == null) {
          throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
        } else {
          return ((Employee) sourceData).getRoom();
        }
      } else if (ENTITYSET_1_5.equals(sourceEntitySet.getName())) {
        List<Room> data = ((Building) sourceData).getRooms();
        if (data.isEmpty()) {
          throw new ODataNotFoundException(null);
        }
        if (targetKeys.isEmpty()) {
          return Arrays.asList(data.toArray());
        } else {
          for (final Object room : data) {
            if (((Room) room).getId().equals(targetKeys.get("Id"))) {
              return room;
            }
          }
        }
        throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
      }
      throw new ODataNotImplementedException();

    } else if (ENTITYSET_1_4.equals(targetEntitySet.getName())) {
      if (((Employee) sourceData).getManager() == null) {
        throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
      } else {
        return ((Employee) sourceData).getManager();
      }

    } else if (ENTITYSET_1_5.equals(targetEntitySet.getName())) {
      if (((Room) sourceData).getBuilding() == null) {
        throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
      } else {
        return ((Room) sourceData).getBuilding();
      }

    } else {
View Full Code Here

  public Object readData(final EdmFunctionImport function, final Map<String, Object> parameters,
      final Map<String, Object> keys) throws ODataNotImplementedException, ODataNotFoundException, EdmException {
    if (function.getName().equals("EmployeeSearch")) {
      if (parameters.get("q") == null) {
        throw new ODataNotFoundException(null);
      } else {
        final List<Employee> found = searchEmployees((String) parameters.get("q"));
        if (keys.isEmpty()) {
          return found;
        } else {
          for (final Employee employee : found) {
            if (employee.getId().equals(keys.get("EmployeeId"))) {
              return employee;
            }
          }
        }
        throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
      }

    } else if (function.getName().equals("AllLocations")) {
      return Arrays.asList(getLocations().keySet().toArray());

    } else if (function.getName().equals("AllUsedRoomIds")) {
      List<String> data = new ArrayList<String>();
      for (final Room room : dataContainer.getRooms()) {
        if (!room.getEmployees().isEmpty()) {
          data.add(room.getId());
        }
      }
      if (data.isEmpty()) {
        throw new ODataNotFoundException(null);
      } else {
        return data;
      }

    } else if (function.getName().equals("MaximalAge")) {
      return getOldestEmployee().getAge();

    } else if (function.getName().equals("MostCommonLocation")) {
      return getMostCommonLocation();

    } else if (function.getName().equals("ManagerPhoto")) {
      if (parameters.get("Id") == null) {
        throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
      }
      for (final Manager manager : dataContainer.getManagers()) {
        if (manager.getId().equals(parameters.get("Id"))) {
          return new BinaryData(manager.getImage(), manager.getImageType());
        }
      }
      throw new ODataNotFoundException(ODataNotFoundException.ENTITY);

    } else if (function.getName().equals("OldestEmployee")) {
      return getOldestEmployee();

    } else {
View Full Code Here

TOP

Related Classes of org.apache.olingo.odata2.api.exception.ODataNotFoundException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.