Submits the entity definitions (instances).
The body contains the JSONArray of entity json. The service takes care of de-duping the entities based on any
unique attribute for the give type.
426710
@POST
    @Consumes({Servlets.JSON_MEDIA_TYPE, MediaType.APPLICATION_JSON})
    @Produces(Servlets.JSON_MEDIA_TYPE)
    public Response submit(@Context HttpServletRequest request) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("==> EntityResource.submit()");
        }

        String entityJson = null;
        AtlasPerfTracer perf = null;
        try {
            if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
                perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityResource.submit()");
            }

            String entities = Servlets.getRequestPayload(request);

            //Handle backward compatibility - if entities is not JSONArray, convert to JSONArray
            try {
                new JSONArray(entities);
            } catch (JSONException e) {
                final String finalEntities = entities;
                entities = new JSONArray() {{
                    put(finalEntities);
                }}.toString();
            }

            entityJson = AtlasClient.toString(new JSONArray(entities));

            if (LOG.isDebugEnabled()) {
                LOG.debug("submitting entities {} ", entityJson);
            }

            AtlasEntitiesWithExtInfo entitiesInfo     = restAdapters.toAtlasEntities(entities);
            EntityMutationResponse   mutationResponse = entityREST.createOrUpdate(entitiesInfo);

            final List<String> guids = restAdapters.getGuids(mutationResponse.getCreatedEntities());

            if (LOG.isDebugEnabled()) {
                LOG.debug("Created entities {}", guids);
            }

            final CreateUpdateEntitiesResult result = restAdapters.toCreateUpdateEntitiesResult(mutationResponse);

            JSONObject response    = getResponse(result);
            URI        locationURI = getLocationURI(guids);

            return Response.created(locationURI).entity(response).build();

        } catch (AtlasBaseException e) {
            LOG.error("Unable to persist entity instance entityDef={}", entityJson, e);
            throw toWebApplicationException(e);
        } catch(EntityExistsException e) {
            LOG.error("Unique constraint violation for entity entityDef={}", entityJson, e);
            throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.CONFLICT));
        } catch (ValueConversionException ve) {
            LOG.error("Unable to persist entity instance due to a deserialization error entityDef={}", entityJson, ve);
            throw new WebApplicationException(Servlets.getErrorResponse(ve.getCause() != null ? ve.getCause() : ve, Response.Status.BAD_REQUEST));
        } catch (AtlasException | IllegalArgumentException e) {
            LOG.error("Unable to persist entity instance entityDef={}", entityJson, e);
            throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
        } catch (WebApplicationException e) {
            LOG.error("Unable to persist entity instance entityDef={}", entityJson, e);
            throw e;
        } catch (Throwable e) {
            LOG.error("Unable to persist entity instance entityDef={}", entityJson, e);
            throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
        } finally {
            AtlasPerfTracer.log(perf);

            if (LOG.isDebugEnabled()) {
                LOG.debug("<== EntityResource.submit()");
            }

        }
    }
1087719
def json_processor(entity):
    '''
    
    '''
    if six.PY2:
        body = entity.fp.read()
    else:
        # https://github.com/cherrypy/cherrypy/pull/1572
        contents = BytesIO()
        body = entity.fp.read(fp_out=contents)
        contents.seek(0)
        body = salt.utils.stringutils.to_unicode(contents.read())
        del contents
    try:
        cherrypy.serving.request.unserialized_data = salt.utils.json.loads(body)
    except ValueError:
        raise cherrypy.HTTPError(400, 'Invalid JSON document')

    cherrypy.serving.request.raw_body = body
943837
def <<(entity)
      url_chunk, options = setup_entity_post_request(entity)
      result = execute_entity_post_request(options, url_chunk)
      if entity.is_new?
        doc = ::Nokogiri::XML(result.body).remove_namespaces!
        primary_key_node = doc.xpath("//content/properties/#{entity.primary_key}").first
        entity[entity.primary_key] = primary_key_node.content unless primary_key_node.nil?
      end

      unless result.code.to_s =~ /^2[0-9][0-9]$/
        entity.errors << ['could not commit entity']
      end

      entity
    end
386676
@Transactional
  @PostMapping(
      value = "/{entityTypeId}",
      headers = "Content-Type=application/x-www-form-urlencoded")
  public void createFromFormPost(
      @PathVariable("entityTypeId") String entityTypeId,
      HttpServletRequest request,
      HttpServletResponse response) {
    Map<String, Object> paramMap = new HashMap<>();
    for (String param : request.getParameterMap().keySet()) {
      String[] values = request.getParameterValues(param);
      String value = values != null ? StringUtils.join(values, ',') : null;
      if (StringUtils.isNotBlank(value)) {
        paramMap.put(param, value);
      }
    }

    createInternal(entityTypeId, paramMap, response);
  }
607274
def _convert_json_response_to_entities(response, property_resolver):
    ''' 
    '''
    if response is None:
        return response

    entities = _list()

    entities.next_marker = _get_continuation_from_response_headers(response)

    root = loads(response.body.decode('utf-8'))

    if 'value' in root:
        for entity in root['value']:
            entities.append(_convert_json_to_entity(entity, 
                                                 property_resolver))
    else:
        entities.append(_convert_json_to_entity(entity, 
                                             property_resolver))

    return entities
517944
def create_instance(res)
      response = res.parsed_response

      # if there was an error, throw it
      raise_error(response['error'], res.code) if response.nil? || response.key?('error')

      # There must be a top level entity
      # This is either one of payment, refund, or collection at present
      begin
        class_name = response['entity'].split('_').collect(&:capitalize).join

        klass = Razorpay.const_get class_name
      rescue NameError
        # Use Entity class if we don't find any
        klass = Razorpay::Entity
      end
      klass.new(response)
    end
1280512
function parseApplications(response) {
  let entities = {};
  Object.keys(response).forEach(key => {
    entities[key] = parseApplication(response[key]);
  });
  return entities;
}
467264
@Override
    public Object getEntityFromDocument(Class<?> entityClass, JsonObject obj, EntityType entityType)
    {
        Object entity = KunderaCoreUtils.createNewInstance(entityClass);
        Set<Attribute> attributes = entityType.getAttributes();
        Iterator<Attribute> iterator = attributes.iterator();
        iterateAndPopulateEntity(entity, obj, iterator);
        return entity;
    }
1166023
private Entity<String> serialize(Object obj, String contentType) throws ClientErrorException {
        if (contentType.startsWith("application/json")) {
            try {
                return Entity.json(jsonMarshaller.serialize(obj));
            } catch (JsonMarshallingException e) {
                String msg = "Failed marshalling object to JSON data for sending to server: "+e.getMessage();
//                throw new ClientErrorException(Response.Status.BAD_REQUEST, e);
                throw new BadRequestServiceException(
                        new RestFaultInfo("BadRequest", Blame.CLIENT,
                                msg, ""+ ErrorCodes.Client.MARSHALLING_FAILED.getCode(),
                                null,
                                Retry.no(), Retry.no(),
                                Response.Status.BAD_REQUEST.getStatusCode(),
                                Response.Status.BAD_REQUEST.getReasonPhrase()
                        ), e
                );
            }
        } else {
            String msg = "Content type \"" + contentType + "\" is not supported.";
//            throw new NotSupportedException(msg);
            throw new BadRequestServiceException(
                    new RestFaultInfo("BadRequest", Blame.CLIENT,
                            msg, ""+ ErrorCodes.Client.UNSUPPORTED_TECHNOLOGY.getCode(),
                            null,
                            Retry.no(), Retry.no(),
                            Response.Status.BAD_REQUEST.getStatusCode(),
                            Response.Status.BAD_REQUEST.getReasonPhrase()
                    )
            );
        }
    }
1017093
private function decodeBody(): void
    {
        if (empty($this->body) || $this->body === null) {
            $this->decodedBody = [];

            return;
        }

        $this->decodedBody = json_decode($this->body, true);

        if (json_last_error() !== JSON_ERROR_NONE) {
            throw new JsonException('The body of the response could not be decoded as JSON.');
        }

        if (!\is_array($this->decodedBody)) {
            $this->decodedBody = [];
        }
    }
141063
def _merge_entity(entity, if_match):
    '''
    
    '''
    _validate_not_none('if_match', if_match)
    _validate_entity(entity)

    request = HTTPRequest()
    request.method = 'MERGE'
    request.headers = [_DEFAULT_CONTENT_TYPE_HEADER,
                        _DEFAULT_ACCEPT_HEADER,
                        ('If-Match', _to_str(if_match))]
    request.body = _get_request_body(_convert_entity_to_json(entity))

    return request
447700
def [](key)
      entity = new_entity
      key_property = entity.get_property(entity.primary_key)
      key_property.value = key

      result = service.execute("#{name}(#{key_property.url_value})")
      entities = service.find_entities(result)
      single_entity_from_xml(entities)
    end
1044895
public JSONArray asJSONArray()
    {
        if ( entity == null ) {
            return null;
        }
        String str = asString();
        try {
            return new JSONArray( str );
        } catch ( JSONException ex ) {
            throw new CStorageException( "Error parsing the JSON response: " + str, ex );
        }
    }
1115697
protected <C extends CrudResponse, T extends CreateEntity> C handleInsertEntity(T entity) {
        Map<String, String> uriVariables = restUriVariablesFactory.getUriVariablesForEntityInsert(BullhornEntityInfo
                .getTypesRestEntityName(entity.getClass()));
        String url = restUrlFactory.assembleEntityUrlForInsert();

        CrudResponse response;

        try {
            String jsonString = restJsonConverter.convertEntityToJsonString(entity);
            response = this.performCustomRequest(url, jsonString, CreateResponse.class, uriVariables, HttpMethod.PUT, null);
        } catch (HttpStatusCodeException error) {
            response = restErrorHandler.handleHttpFourAndFiveHundredErrors(new CreateResponse(), error, entity.getId());
        }

        return (C) response;
    }
1228548
private Referenceable registerInstance(Referenceable referenceable) throws Exception {
        String typeName = referenceable.getTypeName();
        LOG.debug("creating instance of type {}", typeName);

        String entityJSON = InstanceSerialization.toJson(referenceable, true);
        LOG.debug("Submitting new entity {} = {}", referenceable.getTypeName(), entityJSON);
        List<String> guids = getAtlasClient().createEntity(entityJSON);
        LOG.debug("created instance for type {}, guid: {}", typeName, guids);

        return new Referenceable(guids.get(guids.size() - 1), referenceable.getTypeName(), null);
    }
1231948
@PUT
    @Consumes({Servlets.JSON_MEDIA_TYPE, MediaType.APPLICATION_JSON})
    @Produces(Servlets.JSON_MEDIA_TYPE)
    public Response updateEntities(@Context HttpServletRequest request) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("==> EntityResource.updateEntities()");
        }

        String entityJson = null;
        AtlasPerfTracer perf = null;
        try {
            if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
                perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityResource.updateEntities()");
            }

            final String entities = Servlets.getRequestPayload(request);

            entityJson = AtlasClient.toString(new JSONArray(entities));

            if (LOG.isDebugEnabled()) {
                LOG.info("updating entities {} ", entityJson);
            }

            AtlasEntitiesWithExtInfo   entitiesInfo     = restAdapters.toAtlasEntities(entities);
            EntityMutationResponse     mutationResponse = entityREST.createOrUpdate(entitiesInfo);
            CreateUpdateEntitiesResult result           = restAdapters.toCreateUpdateEntitiesResult(mutationResponse);

            if (LOG.isDebugEnabled()) {
                LOG.debug("Updated entities: {}", result.getEntityResult());
            }

            JSONObject response = getResponse(result);
            return Response.ok(response).build();
        } catch (AtlasBaseException e) {
            LOG.error("Unable to persist entity instance entityDef={}", entityJson, e);
            throw toWebApplicationException(e);
        } catch(EntityExistsException e) {
            LOG.error("Unique constraint violation for entityDef={}", entityJson, e);
            throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.CONFLICT));
        } catch (ValueConversionException ve) {
            LOG.error("Unable to persist entity instance due to a deserialization error entityDef={}", entityJson, ve);
            throw new WebApplicationException(Servlets.getErrorResponse(ve.getCause(), Response.Status.BAD_REQUEST));
        } catch (AtlasException | IllegalArgumentException e) {
            LOG.error("Unable to persist entity instance entityDef={}", entityJson, e);
            throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
        } catch (WebApplicationException e) {
            LOG.error("Unable to persist entity instance entityDef={}", entityJson, e);
            throw e;
        } catch (Throwable e) {
            LOG.error("Unable to persist entity instance entityDef={}", entityJson, e);
            throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
        } finally {
            AtlasPerfTracer.log(perf);

            if (LOG.isDebugEnabled()) {
                LOG.debug("<== EntityResource.updateEntities()");
            }
        }
    }
1002208
protected function detectInvalidJsonFields()
    {
        if (json_encode($this->postFields) === false) {
            $invalidFields = array();
            foreach ($this->postFields as $key => $value) {
                if (json_encode($value) === false) {
                    $invalidFields[] = $key;
                }
            }
            throw new EntityException('Invalid data found in field(s): ' . implode(', ', $invalidFields), EntityException::INVALID_FIELDS);
        }
    }