当前位置: 首页>>代码示例>>Java>>正文


Java Entity.getETag方法代码示例

本文整理汇总了Java中org.apache.olingo.commons.api.data.Entity.getETag方法的典型用法代码示例。如果您正苦于以下问题:Java Entity.getETag方法的具体用法?Java Entity.getETag怎么用?Java Entity.getETag使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.olingo.commons.api.data.Entity的用法示例。


在下文中一共展示了Entity.getETag方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: updateMediaEntity

import org.apache.olingo.commons.api.data.Entity; //导入方法依赖的package包/类
@Override
public void updateMediaEntity(final ODataRequest request, final ODataResponse response, final UriInfo uriInfo,
    final ContentType requestFormat, final ContentType responseFormat)
    throws ODataApplicationException, ODataLibraryException {
  final EdmEntitySet edmEntitySet = getEdmEntitySet(uriInfo);
  final EdmEntityType edmEntityType = edmEntitySet.getEntityType();

  Entity entity = readEntity(uriInfo);
  odata.createETagHelper().checkChangePreconditions(entity.getMediaETag(),
      request.getHeaders(HttpHeader.IF_MATCH),
      request.getHeaders(HttpHeader.IF_NONE_MATCH));
  checkRequestFormat(requestFormat);
  dataProvider.setMedia(entity, odata.createFixedFormatDeserializer().binary(request.getBody()),
      requestFormat.toContentTypeString());

  final Return returnPreference = odata.createPreferences(request.getHeaders(HttpHeader.PREFER)).getReturn();
  if (returnPreference == null || returnPreference == Return.REPRESENTATION) {
    response.setContent(serializeEntity(request, entity, edmEntitySet, edmEntityType, responseFormat)
        .getContent());
    response.setStatusCode(HttpStatusCode.OK.getStatusCode());
    response.setHeader(HttpHeader.CONTENT_TYPE, responseFormat.toContentTypeString());
  } else {
    response.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode());
  }
  if (returnPreference != null) {
    response.setHeader(HttpHeader.PREFERENCE_APPLIED,
        PreferencesApplied.with().returnRepresentation(returnPreference).build().toValueString());
  }
  if (entity.getETag() != null) {
    response.setHeader(HttpHeader.ETAG, entity.getETag());
  }
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:33,代码来源:TechnicalEntityProcessor.java

示例2: deleteProperty

import org.apache.olingo.commons.api.data.Entity; //导入方法依赖的package包/类
private void deleteProperty(final ODataRequest request, ODataResponse response, final UriInfo uriInfo,
    final boolean isValue) throws ODataLibraryException, ODataApplicationException {
  final UriInfoResource resource = uriInfo.asUriInfoResource();
  validatePath(resource);
  getEdmEntitySet(uriInfo); // including checks

  Entity entity = readEntity(uriInfo);
  odata.createETagHelper().checkChangePreconditions(entity.getETag(),
      request.getHeaders(HttpHeader.IF_MATCH),
      request.getHeaders(HttpHeader.IF_NONE_MATCH));

  final List<UriResource> resourceParts = resource.getUriResourceParts();
  final int trailing = isValue ? 1 : 0;
  final List<String> path = getPropertyPath(resourceParts, trailing);

  Property property = getPropertyData(entity, path);

  final EdmProperty edmProperty = ((UriResourceProperty) resourceParts.get(resourceParts.size() - trailing - 1))
      .getProperty();

  if (edmProperty.isNullable()) {
    property.setValue(property.getValueType(), edmProperty.isCollection() ? Collections.emptyList() : null);
    dataProvider.updateETag(entity);
    response.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode());
    if (entity.getETag() != null) {
      response.setHeader(HttpHeader.ETAG, entity.getETag());
    }
  } else {
    throw new ODataApplicationException("Not nullable.", HttpStatusCode.BAD_REQUEST.getStatusCode(), Locale.ROOT);
  }
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:32,代码来源:TechnicalPrimitiveComplexProcessor.java

示例3: updateETag

import org.apache.olingo.commons.api.data.Entity; //导入方法依赖的package包/类
public void updateETag(Entity entity) {
  if (entity.getETag() != null) {
    entity.setETag("W/\"" + UUID.randomUUID() + "\"");
  }
}
 
开发者ID:RedHelixOrg,项目名称:RedHelix-1,代码行数:6,代码来源:DataProvider.java

示例4: updateEntity

import org.apache.olingo.commons.api.data.Entity; //导入方法依赖的package包/类
@Override
public void updateEntity(final ODataRequest request, final ODataResponse response, final UriInfo uriInfo,
    final ContentType requestFormat, final ContentType responseFormat)
    throws ODataApplicationException, ODataLibraryException {
  final EdmEntitySet edmEntitySet = getEdmEntitySet(uriInfo);
  final EdmEntityType edmEntityType = edmEntitySet.getEntityType();

  Entity entity;
  try {
    entity = readEntity(uriInfo);
  } catch (ODataApplicationException e) {
    if (e.getStatusCode() == HttpStatusCode.NOT_FOUND.getStatusCode()) {
      // Perform upsert
      createEntity(request, response, uriInfo, requestFormat, responseFormat);
      return;
    } else {
      throw e;
    }
  }

  odata.createETagHelper().checkChangePreconditions(entity.getETag(),
      request.getHeaders(HttpHeader.IF_MATCH),
      request.getHeaders(HttpHeader.IF_NONE_MATCH));
  final ODataDeserializer deserializer = odata.createDeserializer(requestFormat, serviceMetadata);
  final Entity changedEntity = deserializer.entity(request.getBody(), edmEntitySet.getEntityType()).getEntity();

  new RequestValidator(dataProvider,
      true, // Update
      request.getMethod() == HttpMethod.PATCH,
      request.getRawBaseUri()).validate(edmEntitySet, changedEntity);

  dataProvider.update(request.getRawBaseUri(), edmEntitySet, entity, changedEntity,
      request.getMethod() == HttpMethod.PATCH, false);

  final Return returnPreference = odata.createPreferences(request.getHeaders(HttpHeader.PREFER)).getReturn();
  if (returnPreference == null || returnPreference == Return.REPRESENTATION) {
    response.setStatusCode(HttpStatusCode.OK.getStatusCode());
    response.setContent(serializeEntity(request, entity, edmEntitySet, edmEntityType, responseFormat)
        .getContent());
    response.setHeader(HttpHeader.CONTENT_TYPE, responseFormat.toContentTypeString());
  } else {
    response.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode());
  }
  if (returnPreference != null) {
    response.setHeader(HttpHeader.PREFERENCE_APPLIED,
        PreferencesApplied.with().returnRepresentation(returnPreference).build().toValueString());
  }
  if (entity.getETag() != null) {
    response.setHeader(HttpHeader.ETAG, entity.getETag());
  }
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:52,代码来源:TechnicalEntityProcessor.java

示例5: readEntity

import org.apache.olingo.commons.api.data.Entity; //导入方法依赖的package包/类
private void readEntity(final ODataRequest request, final ODataResponse response, final UriInfo uriInfo,
    final ContentType requestedFormat, final boolean isReference)
    throws ODataApplicationException, ODataLibraryException {
  //
  if (odata.createPreferences(request.getHeaders(HttpHeader.PREFER)).hasRespondAsync()) {
    TechnicalAsyncService asyncService = TechnicalAsyncService.getInstance();
    TechnicalEntityProcessor processor = new TechnicalEntityProcessor(dataProvider, serviceMetadata);
    processor.init(odata, serviceMetadata);
    AsyncProcessor<EntityProcessor> asyncProcessor = asyncService.register(processor, EntityProcessor.class);
    asyncProcessor.prepareFor().readEntity(request, response, uriInfo, requestedFormat);
    String location = asyncProcessor.processAsync();
    TechnicalAsyncService.acceptedResponse(response, location);
    //
    return;
  }
  //

  final EdmEntitySet edmEntitySet = getEdmEntitySet(uriInfo);
  
  //for Singleton/$ref edmEntityset will be null throw error
  validateSingletonRef(isReference,edmEntitySet);
 
  EdmEntityType edmEntityType = null;
  edmEntityType = getEdmTypeForContNavProperty(uriInfo);
  final boolean iscontNav = checkIfContNavigation(uriInfo);
  if (edmEntityType == null) {
    edmEntityType = getEdmType(uriInfo, edmEntitySet);
  }

  final Entity entity = readEntity(uriInfo);

  if (odata.createETagHelper().checkReadPreconditions(entity.getETag(),
      request.getHeaders(HttpHeader.IF_MATCH),
      request.getHeaders(HttpHeader.IF_NONE_MATCH))) {
    response.setStatusCode(HttpStatusCode.NOT_MODIFIED.getStatusCode());
    response.setHeader(HttpHeader.ETAG, entity.getETag());
    return;
  }

  final ExpandOption expand = uriInfo.getExpandOption();
  final SelectOption select = uriInfo.getSelectOption();

  final ExpandSystemQueryOptionHandler expandHandler = new ExpandSystemQueryOptionHandler();
  final Entity entitySerialization = expandHandler.transformEntityGraphToTree(entity, edmEntitySet, expand, null);
  expandHandler.applyExpandQueryOptions(entitySerialization, edmEntitySet, expand, uriInfo,
      serviceMetadata.getEdm());

  final SerializerResult serializerResult = isReference ?
      serializeReference(entity, edmEntitySet, requestedFormat) :
      serializeEntity(request, entitySerialization, edmEntitySet, edmEntityType, 
          requestedFormat, expand, select, iscontNav);

  if (entity.getETag() != null) {
    response.setHeader(HttpHeader.ETAG, entity.getETag());
  }
  response.setContent(serializerResult.getContent());
  response.setStatusCode(HttpStatusCode.OK.getStatusCode());
  response.setHeader(HttpHeader.CONTENT_TYPE, requestedFormat.toContentTypeString());
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:60,代码来源:TechnicalEntityProcessor.java

示例6: updateProperty

import org.apache.olingo.commons.api.data.Entity; //导入方法依赖的package包/类
private void updateProperty(final ODataRequest request, ODataResponse response, final UriInfo uriInfo,
    final ContentType requestFormat, final ContentType responseFormat, final RepresentationType representationType)
    throws ODataApplicationException, ODataLibraryException {
  final UriInfoResource resource = uriInfo.asUriInfoResource();
  validatePath(resource);
  final EdmEntitySet edmEntitySet = getEdmEntitySet(resource);

  Entity entity = readEntity(uriInfo);
  odata.createETagHelper().checkChangePreconditions(entity.getETag(),
      request.getHeaders(HttpHeader.IF_MATCH),
      request.getHeaders(HttpHeader.IF_NONE_MATCH));

  final List<UriResource> resourceParts = resource.getUriResourceParts();
  final int trailing = representationType == RepresentationType.VALUE ? 1 : 0;
  final List<String> path = getPropertyPath(resourceParts, trailing);
  final EdmProperty edmProperty = ((UriResourceProperty) resourceParts.get(resourceParts.size() - trailing - 1))
      .getProperty();

  Property property = getPropertyData(entity, path);

  if (representationType == RepresentationType.VALUE) {
    final FixedFormatDeserializer deserializer = odata.createFixedFormatDeserializer();
    final Object value = edmProperty.getType() == odata.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Binary) ?
        deserializer.binary(request.getBody()) :
        deserializer.primitiveValue(request.getBody(), edmProperty);
    dataProvider.updatePropertyValue(property, value);
  } else {
    final Property changedProperty = odata.createDeserializer(requestFormat)
        .property(request.getBody(), edmProperty).getProperty();
    if (changedProperty.isNull() && !edmProperty.isNullable()) {
      throw new ODataApplicationException("Not nullable.", HttpStatusCode.BAD_REQUEST.getStatusCode(), Locale.ROOT);
    }
    dataProvider.updateProperty(edmProperty, property, changedProperty, request.getMethod() == HttpMethod.PATCH);
  }

  dataProvider.updateETag(entity);

  final Return returnPreference = odata.createPreferences(request.getHeaders(HttpHeader.PREFER)).getReturn();
  if (returnPreference == null || returnPreference == Return.REPRESENTATION) {
    response.setStatusCode(HttpStatusCode.OK.getStatusCode());
    if (representationType == RepresentationType.VALUE) {
      response.setContent(
          serializePrimitiveValue(property, edmProperty, (EdmPrimitiveType) edmProperty.getType(), null));
    } else {
      final SerializerResult result = serializeProperty(entity, edmEntitySet, path, property, edmProperty,
          edmProperty.getType(), null, representationType, responseFormat, null, null);
      response.setContent(result.getContent());
    }
    response.setHeader(HttpHeader.CONTENT_TYPE, responseFormat.toContentTypeString());
  } else {
    response.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode());
  }
  if (returnPreference != null) {
    response.setHeader(HttpHeader.PREFERENCE_APPLIED,
        PreferencesApplied.with().returnRepresentation(returnPreference).build().toValueString());
  }
  if (entity.getETag() != null) {
    response.setHeader(HttpHeader.ETAG, entity.getETag());
  }
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:61,代码来源:TechnicalPrimitiveComplexProcessor.java

示例7: writeEntity

import org.apache.olingo.commons.api.data.Entity; //导入方法依赖的package包/类
protected void writeEntity(final ServiceMetadata metadata, final EdmEntityType entityType, final Entity entity,
    final ContextURL contextURL, final ExpandOption expand, Integer toDepth, 
    final SelectOption select, final boolean onlyReference, Set<String> ancestors, 
    String name, final JsonGenerator json)
    throws IOException, SerializerException, DecoderException {
  boolean cycle = false;
  if (expand != null) {
    if (ancestors == null) {
      ancestors = new HashSet<String>();
    }
    cycle = !ancestors.add(getEntityId(entity, entityType, name));
  }
  try {
    json.writeStartObject();
    if (!isODataMetadataNone) {
      // top-level entity
      if (contextURL != null) {
        writeContextURL(contextURL, json);
        writeMetadataETag(metadata, json);
      }
      if (entity.getETag() != null) {
        json.writeStringField(constants.getEtag(), entity.getETag());
      }
      if (entityType.hasStream()) {
        if (entity.getMediaETag() != null) {
          json.writeStringField(constants.getMediaEtag(), entity.getMediaETag());
        }
        if (entity.getMediaContentType() != null) {
          json.writeStringField(constants.getMediaContentType(), entity.getMediaContentType());
        }
        if (entity.getMediaContentSource() != null) {
          json.writeStringField(constants.getMediaReadLink(), entity.getMediaContentSource().toString());
        }
        if (entity.getMediaEditLinks() != null && !entity.getMediaEditLinks().isEmpty()) {
          json.writeStringField(constants.getMediaEditLink(), entity.getMediaEditLinks().get(0).getHref());
        }
      }
    }
    if (cycle || onlyReference) {
      json.writeStringField(constants.getId(), getEntityId(entity, entityType, name));
    } else {
      final EdmEntityType resolvedType = resolveEntityType(metadata, entityType, entity.getType());
      if ((!isODataMetadataNone && !resolvedType.equals(entityType)) || isODataMetadataFull) {
        json.writeStringField(constants.getType(), "#" + entity.getType());
      }
      if ((!isODataMetadataNone && !areKeyPredicateNamesSelected(select, resolvedType)) || isODataMetadataFull) {
        json.writeStringField(constants.getId(), getEntityId(entity, resolvedType, name));
      }
      
      if (isODataMetadataFull) {
        if (entity.getSelfLink() != null) {
          json.writeStringField(constants.getReadLink(), entity.getSelfLink().getHref());
        }
        if (entity.getEditLink() != null) {
          json.writeStringField(constants.getEditLink(), entity.getEditLink().getHref());
        }
      }
      
      writeProperties(metadata, resolvedType, entity.getProperties(), select, json);
      writeExpandedStreamProperties(metadata, resolvedType, entity, expand, toDepth, ancestors, name, json);
      writeNavigationProperties(metadata, resolvedType, entity, expand, toDepth, ancestors, name, json);
      writeOperations(entity.getOperations(), json);      
    }
    json.writeEndObject();
  } finally {
    if (expand != null && !cycle && ancestors != null) {
      ancestors.remove(getEntityId(entity, entityType, name));
    }
  }
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:71,代码来源:ODataJsonSerializer.java

示例8: doContainerSerialize

import org.apache.olingo.commons.api.data.Entity; //导入方法依赖的package包/类
protected void doContainerSerialize(final ResWrap<Entity> container, final JsonGenerator jgen)
    throws IOException, EdmPrimitiveTypeException {

  final Entity entity = container.getPayload();

  jgen.writeStartObject();

  if (serverMode) {
    if (container.getContextURL() != null) {
      jgen.writeStringField(Constants.JSON_CONTEXT, container.getContextURL().toASCIIString());
    }
    if (container.getMetadataETag() != null) {
      jgen.writeStringField(Constants.JSON_METADATA_ETAG, container.getMetadataETag());
    }

    if (entity.getETag() != null) {
      jgen.writeStringField(Constants.JSON_ETAG, entity.getETag());
    }
  }

  if (entity.getType() != null && !isODataMetadataNone) {
    jgen.writeStringField(Constants.JSON_TYPE,
        new EdmTypeInfo.Builder().setTypeExpression(entity.getType()).build().external());
  }

  if (entity.getId() != null && !isODataMetadataNone) {
    jgen.writeStringField(Constants.JSON_ID, entity.getId().toASCIIString());
  }

  for (Annotation annotation : entity.getAnnotations()) {
    valuable(jgen, annotation, "@" + annotation.getTerm());
  }

  for (Property property : entity.getProperties()) {
    valuable(jgen, property, property.getName());
  }

  if (serverMode && entity.getEditLink() != null && entity.getEditLink().getHref() != null) {
    jgen.writeStringField(Constants.JSON_EDIT_LINK, entity.getEditLink().getHref());

    if (entity.isMediaEntity()) {
      jgen.writeStringField(Constants.JSON_MEDIA_READ_LINK,
          entity.getEditLink().getHref() + "/$value");
    }
  }

  if (!isODataMetadataNone) {
    links(entity, jgen);
  }

  for (Link link : entity.getMediaEditLinks()) {
    if (link.getTitle() == null) {
      jgen.writeStringField(Constants.JSON_MEDIA_EDIT_LINK, link.getHref());
    }

    if (link.getInlineEntity() != null) {
      jgen.writeObjectField(link.getTitle(), link.getInlineEntity());
    }
    if (link.getInlineEntitySet() != null) {
      jgen.writeArrayFieldStart(link.getTitle());
      for (Entity subEntry : link.getInlineEntitySet().getEntities()) {
        jgen.writeObject(subEntry);
      }
      jgen.writeEndArray();
    }
  }

  if (serverMode) {
    for (Operation operation : entity.getOperations()) {
      final String anchor = operation.getMetadataAnchor();
      final int index = anchor.lastIndexOf('#');
      jgen.writeObjectFieldStart('#' + anchor.substring(index < 0 ? 0 : (index + 1)));
      jgen.writeStringField(Constants.ATTR_TITLE, operation.getTitle());
      jgen.writeStringField(Constants.ATTR_TARGET, operation.getTarget().toASCIIString());
      jgen.writeEndObject();
    }
  }

  jgen.writeEndObject();
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:81,代码来源:JsonEntitySerializer.java


注:本文中的org.apache.olingo.commons.api.data.Entity.getETag方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。