예제 #1
0
  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();
  }
예제 #2
0
 private static EdmProperty mockEdmPropertyOfSource1() {
   EdmProperty edmProperty = EasyMock.createMock(EdmProperty.class);
   EdmType type = EasyMock.createMock(EdmType.class);
   EasyMock.expect(type.getKind()).andStubReturn(EdmTypeKind.SIMPLE);
   EasyMock.replay(type);
   EdmMapping mapping = EasyMock.createMock(EdmMapping.class);
   EasyMock.expect(mapping.getInternalName()).andStubReturn("id");
   EasyMock.replay(mapping);
   try {
     EasyMock.expect(edmProperty.getName()).andStubReturn("id");
     EasyMock.expect(edmProperty.getType()).andStubReturn(type);
     EasyMock.expect(edmProperty.getMapping()).andStubReturn(mapping);
   } catch (EdmException e) {
     fail(
         ODataJPATestConstants.EXCEPTION_MSG_PART_1
             + e.getMessage()
             + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
   }
   EasyMock.replay(edmProperty);
   return edmProperty;
 }