Java Code Examples for org.apache.olingo.odata2.api.edm.EdmProperty#getFacets()

The following examples show how to use org.apache.olingo.odata2.api.edm.EdmProperty#getFacets() . 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: AtomEntrySerializerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void testExceptionWithNonNullablePropertyIsNull1() throws Exception {
  EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Organizations");
  EdmProperty kindProperty = (EdmProperty) entitySet.getEntityType().getProperty("Kind");
  EdmFacets facets = kindProperty.getFacets();
  when(facets.isNullable()).thenReturn(new Boolean(false));
  
  EdmProperty nameProperty = (EdmProperty) entitySet.getEntityType().getProperty("Name");
  when(nameProperty.getFacets()).thenReturn(null);
  
  Entity orgData = new Entity();
  orgData.addProperty("Id", "1");
  orgData.addProperty("Name", "Org1");
  orgData.setWriteProperties(EntitySerializerProperties.serviceRoot(BASE_URI).build());
  try {
    createAtomEntityProvider().writeEntry(entitySet, orgData);
  } catch (EntityProviderProducerException e) {
    assertTrue(e.getMessage().contains("The metadata do not allow a null value for property 'Kind'"));
  }
}
 
Example 2
Source File: JsonEntryEntitySerializerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void testExceptionWithNonNullablePropertyIsNull2() throws Exception {
  EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Organizations");
  EdmProperty kindProperty = (EdmProperty) entitySet.getEntityType().getProperty("Kind");
  EdmFacets facets = kindProperty.getFacets();
  when(facets.isNullable()).thenReturn(new Boolean(false));
  
  EdmProperty nameProperty = (EdmProperty) entitySet.getEntityType().getProperty("Name");
  EdmFacets facets1 = nameProperty.getFacets();
  when(facets1.isNullable()).thenReturn(new Boolean(false));
   
  Entity orgData = new Entity();
  orgData.addProperty("Id", "1");
  orgData.addProperty("Name", "Org1");
  orgData.setWriteProperties(
      EntitySerializerProperties.serviceRoot(URI.create(BASE_URI)).build());
  try {
    new JsonSerializerDeserializer().writeEntry(entitySet, orgData);
  } catch (EntityProviderProducerException e) {
    assertTrue(e.getMessage().contains("do not allow to format the value 'Org1' for property 'Name'."));
  }
}
 
Example 3
Source File: AtomEntrySerializerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void testExceptionWithNonNullablePropertyIsNull2() throws Exception {
  EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Organizations");
  EdmProperty kindProperty = (EdmProperty) entitySet.getEntityType().getProperty("Kind");
  EdmFacets facets = kindProperty.getFacets();
  when(facets.isNullable()).thenReturn(new Boolean(false));
  
  EdmProperty nameProperty = (EdmProperty) entitySet.getEntityType().getProperty("Name");
  EdmFacets facets1 = nameProperty.getFacets();
  when(facets1.isNullable()).thenReturn(new Boolean(false));
   
  Entity orgData = new Entity();
  orgData.addProperty("Id", "1");
  orgData.addProperty("Name", "Org1");
  orgData.setWriteProperties(EntitySerializerProperties.serviceRoot(BASE_URI).build());
  try {
    createAtomEntityProvider().writeEntry(entitySet, orgData);
  } catch (EntityProviderProducerException e) {
    assertTrue(e.getMessage().contains("do not allow to format the value 'Org1' for property 'Name'."));
  }
}
 
Example 4
Source File: JsonEntryEntitySerializerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void testExceptionWithNonNullablePropertyIsNull() throws Exception {
  EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Organizations");
  EdmProperty nameProperty = (EdmProperty) entitySet.getEntityType().getProperty("Name");
  EdmFacets facets = nameProperty.getFacets();
  when(facets.isNullable()).thenReturn(new Boolean(false));
  
  Entity orgData = new Entity();
  orgData.addProperty("Id", "1");
  orgData.setWriteProperties(
      EntitySerializerProperties.serviceRoot(URI.create(BASE_URI)).build());
  try {
    new JsonSerializerDeserializer().writeEntry(entitySet, orgData);
  } catch (EntityProviderProducerException e) {
    assertTrue(e.getMessage().contains("The metadata do not allow a null value for property 'Name'"));
  }
}
 
Example 5
Source File: AtomEntrySerializerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void testExceptionWithNonNullablePropertyIsNull() throws Exception {
  EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Organizations");
  EdmProperty nameProperty = (EdmProperty) entitySet.getEntityType().getProperty("Name");
  EdmFacets facets = nameProperty.getFacets();
  when(facets.isNullable()).thenReturn(new Boolean(false));
  
  Entity orgData = new Entity();
  orgData.addProperty("Id", "1");
  orgData.setWriteProperties(EntitySerializerProperties.serviceRoot(BASE_URI).build());
  try {
    createAtomEntityProvider().writeEntry(entitySet, orgData);
  } catch (EntityProviderProducerException e) {
    assertTrue(e.getMessage().contains("The metadata do not allow a null value for property 'Name'"));
  }
}
 
Example 6
Source File: JsonEntryEntityProducerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void testExceptionWithNonNullablePropertyIsNull1() throws Exception {
  EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Organizations");
  EdmProperty kindProperty = (EdmProperty) entitySet.getEntityType().getProperty("Kind");
  EdmFacets facets = kindProperty.getFacets();
  when(facets.isNullable()).thenReturn(new Boolean(false));
  
  EdmProperty nameProperty = (EdmProperty) entitySet.getEntityType().getProperty("Name");
  when(nameProperty.getFacets()).thenReturn(null);
  final EntityProviderWriteProperties properties =
      EntityProviderWriteProperties.serviceRoot(URI.create(BASE_URI)).omitETag(true).
      isDataBasedPropertySerialization(true).build();
  
  Map<String, Object> orgData = new HashMap<String, Object>();
  orgData.put("Id", "1");
  orgData.put("Name", "Org1");
  try {
    new JsonEntityProvider().writeEntry(entitySet, orgData, properties);
  } catch (EntityProviderProducerException e) {
    assertTrue(e.getMessage().contains("The metadata do not allow a null value for property 'Kind'"));
  }
}
 
Example 7
Source File: JsonEntryEntityProducerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void testExceptionWithNonNullablePropertyIsNull() throws Exception {
  EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Organizations");
  EdmProperty nameProperty = (EdmProperty) entitySet.getEntityType().getProperty("Name");
  EdmFacets facets = nameProperty.getFacets();
  when(facets.isNullable()).thenReturn(new Boolean(false));
  final EntityProviderWriteProperties properties =
      EntityProviderWriteProperties.serviceRoot(URI.create(BASE_URI)).omitETag(true).
      isDataBasedPropertySerialization(true).build();
  
  Map<String, Object> orgData = new HashMap<String, Object>();
  orgData.put("Id", "1");
  try {
    new JsonEntityProvider().writeEntry(entitySet, orgData, properties);
  } catch (EntityProviderProducerException e) {
    assertTrue(e.getMessage().contains("The metadata do not allow a null value for property 'Name'"));
  }
}
 
Example 8
Source File: AtomEntryProducerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void testExceptionWithNonNullablePropertyIsNull2() throws Exception {
  EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Organizations");
  EdmProperty kindProperty = (EdmProperty) entitySet.getEntityType().getProperty("Kind");
  EdmFacets facets = kindProperty.getFacets();
  when(facets.isNullable()).thenReturn(new Boolean(false));
  
  EdmProperty nameProperty = (EdmProperty) entitySet.getEntityType().getProperty("Name");
  EdmFacets facets1 = nameProperty.getFacets();
  when(facets1.isNullable()).thenReturn(new Boolean(false));
  final EntityProviderWriteProperties properties =
      EntityProviderWriteProperties.serviceRoot(BASE_URI).omitETag(true).
      isDataBasedPropertySerialization(true).build();
  AtomEntityProvider ser = createAtomEntityProvider();

  Map<String, Object> orgData = new HashMap<String, Object>();
  orgData.put("Id", "1");
  orgData.put("Name", "Org1");
  try {
  ser.writeEntry(entitySet, orgData, properties);
  } catch (EntityProviderProducerException e) {
    assertTrue(e.getMessage().contains("do not allow to format the value 'Org1' for property 'Name'."));
  }
}
 
Example 9
Source File: AtomEntryProducerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void testExceptionWithNonNullablePropertyIsNull1() throws Exception {
  EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Organizations");
  EdmProperty kindProperty = (EdmProperty) entitySet.getEntityType().getProperty("Kind");
  EdmFacets facets = kindProperty.getFacets();
  when(facets.isNullable()).thenReturn(new Boolean(false));
  
  EdmProperty nameProperty = (EdmProperty) entitySet.getEntityType().getProperty("Name");
  when(nameProperty.getFacets()).thenReturn(null);
  final EntityProviderWriteProperties properties =
      EntityProviderWriteProperties.serviceRoot(BASE_URI).omitETag(true).
      isDataBasedPropertySerialization(true).build();
  AtomEntityProvider ser = createAtomEntityProvider();

  Map<String, Object> orgData = new HashMap<String, Object>();
  orgData.put("Id", "1");
  orgData.put("Name", "Org1");
  try {
  ser.writeEntry(entitySet, orgData, properties);
  } catch (EntityProviderProducerException e) {
    assertTrue(e.getMessage().contains("The metadata do not allow a null value for property 'Kind'"));
  }
}
 
Example 10
Source File: AtomEntryProducerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void testExceptionWithNonNullablePropertyIsNull() throws Exception {
  EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Organizations");
  EdmProperty nameProperty = (EdmProperty) entitySet.getEntityType().getProperty("Name");
  EdmFacets facets = nameProperty.getFacets();
  when(facets.isNullable()).thenReturn(new Boolean(false));
  final EntityProviderWriteProperties properties =
      EntityProviderWriteProperties.serviceRoot(BASE_URI).omitETag(true).
      isDataBasedPropertySerialization(true).build();
  AtomEntityProvider ser = createAtomEntityProvider();

  Map<String, Object> orgData = new HashMap<String, Object>();
  orgData.put("Id", "1");
  try {
  ser.writeEntry(entitySet, orgData, properties);
  } catch (EntityProviderProducerException e) {
    assertTrue(e.getMessage().contains("The metadata do not allow a null value for property 'Name'"));
  }
}
 
Example 11
Source File: AtomEntryProducerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void omitETagTestNonNullablePropertyNOTPresentMustNotResultInException() throws Exception {
  EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Rooms");
  EdmProperty versionProperty = (EdmProperty) entitySet.getEntityType().getProperty("Version");
  EdmFacets facets = versionProperty.getFacets();
  when(facets.isNullable()).thenReturn(new Boolean(false));
  List<String> selectedPropertyNames = new ArrayList<String>();
  selectedPropertyNames.add("Id");
  selectedPropertyNames.add("Name");
  selectedPropertyNames.add("Seats");
  ExpandSelectTreeNode selectNode =
      ExpandSelectTreeNode.entitySet(entitySet).selectedProperties(selectedPropertyNames).build();
  final EntityProviderWriteProperties properties =
      EntityProviderWriteProperties.serviceRoot(BASE_URI).omitETag(true).expandSelectTree(selectNode).build();
  AtomEntityProvider ser = createAtomEntityProvider();

  Map<String, Object> localRoomData = new HashMap<String, Object>();
  localRoomData.put("Id", "1");
  localRoomData.put("Name", "Neu Schwanstein");
  localRoomData.put("Seats", new Integer(20));
  ODataResponse response = ser.writeEntry(entitySet, localRoomData, properties);
  String xmlString = verifyResponse(response);
  assertXpathNotExists("/a:entry[@m:etag]", xmlString);
}
 
Example 12
Source File: JsonEntryEntityProducerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void omitETagTestNonNullablePropertyNOTPresentMustNotResultInException() throws Exception {
  EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Rooms");
  EdmProperty versionProperty = (EdmProperty) entitySet.getEntityType().getProperty("Version");
  EdmFacets facets = versionProperty.getFacets();
  when(facets.isNullable()).thenReturn(new Boolean(false));
  List<String> selectedPropertyNames = new ArrayList<String>();
  selectedPropertyNames.add("Id");
  selectedPropertyNames.add("Name");
  selectedPropertyNames.add("Seats");
  ExpandSelectTreeNode selectNode =
      ExpandSelectTreeNode.entitySet(entitySet).selectedProperties(selectedPropertyNames).build();
  final EntityProviderWriteProperties properties =
      EntityProviderWriteProperties.serviceRoot(URI.create(BASE_URI)).omitETag(true).omitJsonWrapper(true)
          .expandSelectTree(selectNode).build();
  Map<String, Object> localRoomData = new HashMap<String, Object>();
  localRoomData.put("Id", "1");
  localRoomData.put("Name", "Neu Schwanstein");
  localRoomData.put("Seats", new Integer(20));
  final ODataResponse response = new JsonEntityProvider().writeEntry(entitySet, localRoomData, properties);
  Map<String, Object> room =
      (Map<String, Object>) new Gson().fromJson(new InputStreamReader((InputStream) response.getEntity()), Map.class);

  room = (Map<String, Object>) room.get("__metadata");
  assertFalse(room.containsKey("etag"));
}
 
Example 13
Source File: EntityInfoAggregator.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private void checkETagRelevant(final EdmProperty edmProperty) throws EntityProviderException {
  try {
    if (edmProperty.getFacets() != null && edmProperty.getFacets().getConcurrencyMode() == EdmConcurrencyMode.Fixed) {
      etagPropertyNames.add(edmProperty.getName());
    }
  } catch (EdmException e) {
    throw new EntityProviderException(EntityProviderException.COMMON, e);
  }
}
 
Example 14
Source File: XmlEntityConsumerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
/**
 * Missing _d_ namespace at non-nullable property/tag (_Version_) is allowed.
 * @throws Exception
 */
public void validationOfNamespacesMissingD_NamespaceAtNonNullableTag() throws Exception {
  String roomWithValidNamespaces =
      "<?xml version='1.0' encoding='UTF-8'?>"
          +
          "<entry xmlns=\"http://www.w3.org/2005/Atom\" " +
          "xmlns:m=\"http://schemas.microsoft.com/ado/2007/08/dataservices/metadata\" " +
          "xmlns:d=\"http://schemas.microsoft.com/ado/2007/08/dataservices\" " +
          "xml:base=\"http://localhost:19000/test/\" m:etag=\"W/&quot;1&quot;\">"
          +
          "  <id>http://localhost:19000/test/Rooms('1')</id>" +
          "  <title type=\"text\">Room 1</title>" +
          "  <updated>2013-01-11T13:50:50.541+01:00</updated>" +
          "  <content type=\"application/xml\">" +
          "    <m:properties>" +
          "      <d:Seats>11</d:Seats>" +
          "      <d:Name>Room 42</d:Name>" +
          "      <Version>4711</Version>" +
          "    </m:properties>" +
          "  </content>" +
          "</entry>";

  final EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Rooms");
  final EdmProperty property = (EdmProperty) entitySet.getEntityType().getProperty("Version");
  EdmFacets facets = property.getFacets();
  Mockito.when(facets.isNullable()).thenReturn(false);

  InputStream reqContent = createContentAsStream(roomWithValidNamespaces);
  final ODataEntry result =
      new XmlEntityConsumer().readEntry(entitySet, reqContent, EntityProviderReadProperties.init().mergeSemantic(
          false).build());
  assertNotNull(result);
}
 
Example 15
Source File: ListsProcessor.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private <T> String constructETag(final EdmEntitySet entitySet, final T data) throws ODataException {
  final EdmEntityType entityType = entitySet.getEntityType();
  String eTag = null;
  for (final String propertyName : entityType.getPropertyNames()) {
    final EdmProperty property = (EdmProperty) entityType.getProperty(propertyName);
    if (property.getFacets() != null && property.getFacets().getConcurrencyMode() == EdmConcurrencyMode.Fixed) {
      final EdmSimpleType type = (EdmSimpleType) property.getType();
      final String component = type.valueToString(valueAccess.getPropertyValue(data, property),
          EdmLiteralKind.DEFAULT, property.getFacets());
      eTag = eTag == null ? component : eTag + Edm.DELIMITER + component;
    }
  }
  return eTag == null ? null : "W/\"" + eTag + "\"";
}
 
Example 16
Source File: XmlEntityDeserializerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
/**
 * Missing _d_ namespace at non-nullable property/tag (_Version_) is allowed.
 * @throws Exception
 */
public void validationOfNamespacesMissingD_NamespaceAtNonNullableTag() throws Exception {
  String roomWithValidNamespaces =
      "<?xml version='1.0' encoding='UTF-8'?>"
          +
          "<entry xmlns=\"http://www.w3.org/2005/Atom\" " +
          "xmlns:m=\"http://schemas.microsoft.com/ado/2007/08/dataservices/metadata\" " +
          "xmlns:d=\"http://schemas.microsoft.com/ado/2007/08/dataservices\" " +
          "xml:base=\"http://localhost:19000/test/\" m:etag=\"W/&quot;1&quot;\">"
          +
          "  <id>http://localhost:19000/test/Rooms('1')</id>" +
          "  <title type=\"text\">Room 1</title>" +
          "  <updated>2013-01-11T13:50:50.541+01:00</updated>" +
          "  <content type=\"application/xml\">" +
          "    <m:properties>" +
          "      <d:Seats>11</d:Seats>" +
          "      <d:Name>Room 42</d:Name>" +
          "      <Version>4711</Version>" +
          "    </m:properties>" +
          "  </content>" +
          "</entry>";

  final EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Rooms");
  final EdmProperty property = (EdmProperty) entitySet.getEntityType().getProperty("Version");
  EdmFacets facets = property.getFacets();
  Mockito.when(facets.isNullable()).thenReturn(false);

  InputStream reqContent = createContentAsStream(roomWithValidNamespaces);
  EntityStream stream = new EntityStream();
  stream.setContent(reqContent);
  stream.setReadProperties(DeserializerProperties.init().build());

  // execute
  XmlEntityDeserializer xec = new XmlEntityDeserializer();
  ODataEntry result = xec.readEntry(entitySet, stream);
  assertNotNull(result);
}
 
Example 17
Source File: EntityComplexPropertyInfo.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
static EntityComplexPropertyInfo create(final EdmProperty property, final List<String> propertyNames,
    final Map<String, EntityPropertyInfo> childEntityInfos) throws EdmException {
  List<EntityPropertyInfo> childEntityInfoList = new ArrayList<EntityPropertyInfo>(childEntityInfos.size());
  for (String name : propertyNames) {
    childEntityInfoList.add(childEntityInfos.get(name));
  }

  EntityComplexPropertyInfo info = new EntityComplexPropertyInfo(
      property.getName(),
      property.getType(),
      property.getFacets(),
      property.getCustomizableFeedMappings(),
      childEntityInfoList);
  return info;
}
 
Example 18
Source File: EntityPropertyInfo.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
static EntityPropertyInfo create(final EdmProperty property) throws EdmException {
  return new EntityPropertyInfo(
      property.getName(),
      property.getType(),
      property.getFacets(),
      property.getCustomizableFeedMappings(),
      property.getMimeType(),
      property.getMapping());
}
 
Example 19
Source File: ListsProcessor.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private <T> String constructETag(final EdmEntitySet entitySet, final T data) throws ODataException {
  final EdmEntityType entityType = entitySet.getEntityType();
  String eTag = null;
  for (final String propertyName : entityType.getPropertyNames()) {
    final EdmProperty property = (EdmProperty) entityType.getProperty(propertyName);
    if (property.getFacets() != null && property.getFacets().getConcurrencyMode() == EdmConcurrencyMode.Fixed) {
      final EdmSimpleType type = (EdmSimpleType) property.getType();
      final String component = type.valueToString(valueAccess.getPropertyValue(data, property),
          EdmLiteralKind.DEFAULT, property.getFacets());
      eTag = eTag == null ? component : eTag + Edm.DELIMITER + component;
    }
  }
  return eTag == null ? null : "W/\"" + eTag + "\"";
}
 
Example 20
Source File: ODataRequestHandler.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
private static boolean isPropertyNullable(final EdmProperty property) throws EdmException {
  return property != null && (property.getFacets() == null || property.getFacets().isNullable());
}