putSample(params, userName) {
    const now = new Date().toISOString();
    const reqBody = params.queryBody.value;
    const sampleName = params.key.value;
    const parsedSampleName = parseName(sampleName);
    const subjectAbsolutePath = parsedSampleName.subject.absolutePath;
    const aspectName = parsedSampleName.aspect.name;
    let currSampObj;
    let aspectObj;
    return redisOps.getHashPromise(sampleType, sampleName)
    .then((sampObj) => {
      if (!sampObj) {
        throw new redisErrors.ResourceNotFoundError({
          explanation: 'Sample not found.',
        });
      }

      currSampObj = sampObj;
      return redisOps.getHashPromise(aspectType, aspectName);
    })
    .then((aspObj) => {
      if (!aspObj || (aspObj.isPublished == 'false')) {
        throw new redisErrors.ResourceNotFoundError({
          explanation: 'Aspect not found.',
        });
      }

      aspectObj = sampleStore.arrayObjsStringsToJson(
        aspObj, constants.fieldsToStringify.aspect
      );

      return redisOps.getHashPromise(subjectType, subjectAbsolutePath);
    })
    .then((subjObj) => {
      if (!subjObj || (subjObj.isPublished == 'false')) {
        throw new redisErrors.ResourceNotFoundError({
          explanation: 'Subject not found.',
        });
      }

      return checkWritePermission(aspectObj, userName);
    })
    .then(() => {
      modelUtils.removeExtraAttributes(reqBody, sampleFieldsArr);
      let value = '';
      if (reqBody.value) {
        value = reqBody.value;
      }

      // change these only if status is updated
      const status = sampleUtils.computeStatus(aspectObj, value);
      if (currSampObj[sampFields.STATUS] !== status) {
        reqBody[sampFields.PRVS_STATUS] = currSampObj[sampFields.STATUS];
        reqBody[sampFields.STS_CHANGED_AT] = now;
        reqBody[sampFields.STATUS] = status;
      }

      // We have a value, so update value and updated_at always.
      reqBody[sampFields.VALUE] = value;
      reqBody[sampFields.UPD_AT] = now;

      if (reqBody.relatedLinks) { // related links
        reqBody[sampFields.RLINKS] = JSON.stringify(reqBody.relatedLinks);
      } else {
        reqBody[sampFields.RLINKS] = '[]';
      }

      const cmds = [];

      // delete fields with future null value
      if (!reqBody.messageBody) {
        cmds.push(
          redisOps.delHashFieldCmd(sampleType, sampleName, sampFields.MSG_BODY)
        );
      }

      if (!reqBody.messageCode) {
        cmds.push(
          redisOps.delHashFieldCmd(sampleType, sampleName, sampFields.MSG_CODE)
        );
      }

      cmds.push(redisOps.setHashMultiCmd(sampleType, sampleName, reqBody));
      return redisOps.executeBatchCmds(cmds);
    })
    .then(() => redisOps.getHashPromise(sampleType, sampleName))
    .then((updatedSamp) => {
      parseName(updatedSamp.name); // throw if invalid name
      return cleanAddAspectToSample(updatedSamp, aspectObj);
    });
  }
/**
   * Put sample. First get sample. If not found, throw error. Get aspect.
   * Update request body with required fields based on value and related links
   * if needed. Delete message body and message code fields from hash
   * if not provided because they will be null. Then update sample.
   *
   * @param  {Object} params - Request parameters
   * @param {String} userName - The user performing the write operation
   * @returns {Promise} - Resolves to a sample object
   */
Put sample. First get sample. If not found, throw error. Get aspect.
Update request body with required fields based on value and related links
if needed. Delete message body and message code fields from hash
if not provided because they will be null. Then update sample.

@param  {Object} params - Request parameters
@param {String} userName - The user performing the write operation
@returns {Promise} - Resolves to a sample object
Put sample . First get sample . If not found throw error . Get aspect . Update request body with required fields based on value and related links if needed . Delete message body and message code fields from hash if not provided because they will be null . Then update sample . @param { Object } params - Request parameters @param { String } userName - The user performing the write operation @returns { Promise } - Resolves to a sample object
putSample(params, userName) {
    const now = new Date().toISOString();
    const reqBody = params.queryBody.value;
    const sampleName = params.key.value;
    const parsedSampleName = parseName(sampleName);
    const subjectAbsolutePath = parsedSampleName.subject.absolutePath;
    const aspectName = parsedSampleName.aspect.name;
    let currSampObj;
    let aspectObj;
    return redisOps.getHashPromise(sampleType, sampleName)
    .then((sampObj) => {
      if (!sampObj) {
        throw new redisErrors.ResourceNotFoundError({
          explanation: 'Sample not found.',
        });
      }
      currSampObj = sampObj;
      return redisOps.getHashPromise(aspectType, aspectName);
    })
    .then((aspObj) => {
      if (!aspObj || (aspObj.isPublished == 'false')) {
        throw new redisErrors.ResourceNotFoundError({
          explanation: 'Aspect not found.',
        });
      }
      aspectObj = sampleStore.arrayObjsStringsToJson(
        aspObj, constants.fieldsToStringify.aspect
      );
      return redisOps.getHashPromise(subjectType, subjectAbsolutePath);
    })
    .then((subjObj) => {
      if (!subjObj || (subjObj.isPublished == 'false')) {
        throw new redisErrors.ResourceNotFoundError({
          explanation: 'Subject not found.',
        });
      }
      return checkWritePermission(aspectObj, userName);
    })
    .then(() => {
      modelUtils.removeExtraAttributes(reqBody, sampleFieldsArr);
      let value = '';
      if (reqBody.value) {
        value = reqBody.value;
      }
      const status = sampleUtils.computeStatus(aspectObj, value);
      if (currSampObj[sampFields.STATUS] !== status) {
        reqBody[sampFields.PRVS_STATUS] = currSampObj[sampFields.STATUS];
        reqBody[sampFields.STS_CHANGED_AT] = now;
        reqBody[sampFields.STATUS] = status;
      }
      reqBody[sampFields.VALUE] = value;
      reqBody[sampFields.UPD_AT] = now;
      if (reqBody.relatedLinks) { 
        reqBody[sampFields.RLINKS] = JSON.stringify(reqBody.relatedLinks);
      } else {
        reqBody[sampFields.RLINKS] = '[]';
      }
      const cmds = [];
      if (!reqBody.messageBody) {
        cmds.push(
          redisOps.delHashFieldCmd(sampleType, sampleName, sampFields.MSG_BODY)
        );
      }
      if (!reqBody.messageCode) {
        cmds.push(
          redisOps.delHashFieldCmd(sampleType, sampleName, sampFields.MSG_CODE)
        );
      }
      cmds.push(redisOps.setHashMultiCmd(sampleType, sampleName, reqBody));
      return redisOps.executeBatchCmds(cmds);
    })
    .then(() => redisOps.getHashPromise(sampleType, sampleName))
    .then((updatedSamp) => {
      parseName(updatedSamp.name); 
      return cleanAddAspectToSample(updatedSamp, aspectObj);
    });
  }
putSample ( params , userName ) { const now = new Date ( ) . toISOString ( ) ; const reqBody = params . queryBody . value ; const sampleName = params . key . value ; const parsedSampleName = parseName ( sampleName ) ; const subjectAbsolutePath = parsedSampleName . subject . absolutePath ; const aspectName = parsedSampleName . aspect . name ; let currSampObj ; let aspectObj ; return redisOps . getHashPromise ( sampleType , sampleName ) . then ( ( sampObj ) => { if ( ! sampObj ) { throw new redisErrors . ResourceNotFoundError ( { explanation : 'Sample not found.' , } ) ; } currSampObj = sampObj ; return redisOps . getHashPromise ( aspectType , aspectName ) ; } ) . then ( ( aspObj ) => { if ( ! aspObj || ( aspObj . isPublished == 'false' ) ) { throw new redisErrors . ResourceNotFoundError ( { explanation : 'Aspect not found.' , } ) ; } aspectObj = sampleStore . arrayObjsStringsToJson ( aspObj , constants . fieldsToStringify . aspect ) ; return redisOps . getHashPromise ( subjectType , subjectAbsolutePath ) ; } ) . then ( ( subjObj ) => { if ( ! subjObj || ( subjObj . isPublished == 'false' ) ) { throw new redisErrors . ResourceNotFoundError ( { explanation : 'Subject not found.' , } ) ; } return checkWritePermission ( aspectObj , userName ) ; } ) . then ( ( ) => { modelUtils . removeExtraAttributes ( reqBody , sampleFieldsArr ) ; let value = '' ; if ( reqBody . value ) { value = reqBody . value ; } const status = sampleUtils . computeStatus ( aspectObj , value ) ; if ( currSampObj [ sampFields . STATUS ] !== status ) { reqBody [ sampFields . PRVS_STATUS ] = currSampObj [ sampFields . STATUS ] ; reqBody [ sampFields . STS_CHANGED_AT ] = now ; reqBody [ sampFields . STATUS ] = status ; } reqBody [ sampFields . VALUE ] = value ; reqBody [ sampFields . UPD_AT ] = now ; if ( reqBody . relatedLinks ) { reqBody [ sampFields . RLINKS ] = JSON . stringify ( reqBody . relatedLinks ) ; } else { reqBody [ sampFields . RLINKS ] = '[]' ; } const cmds = [ ] ; if ( ! reqBody . messageBody ) { cmds . push ( redisOps . delHashFieldCmd ( sampleType , sampleName , sampFields . MSG_BODY ) ) ; } if ( ! reqBody . messageCode ) { cmds . push ( redisOps . delHashFieldCmd ( sampleType , sampleName , sampFields . MSG_CODE ) ) ; } cmds . push ( redisOps . setHashMultiCmd ( sampleType , sampleName , reqBody ) ) ; return redisOps . executeBatchCmds ( cmds ) ; } ) . then ( ( ) => redisOps . getHashPromise ( sampleType , sampleName ) ) . then ( ( updatedSamp ) => { parseName ( updatedSamp . name ) ; return cleanAddAspectToSample ( updatedSamp , aspectObj ) ; } ) ; }
Put sample.
Put sample .
// change these only if status is updated // We have a value, so update value and updated_at always. // related links // delete fields with future null value // throw if invalid name