/* (non-Javadoc)
   * @see sif3.common.interfaces.Provider#createMany(java.lang.Object, sif3.common.model.SIFZone, sif3.common.model.SIFContext)
   */
  @Override
  public List<CreateOperationStatus> createMany(
      Object data,
      boolean useAdvisory,
      SIFZone zone,
      SIFContext context,
      RequestMetadata metadata,
      ResponseParameters customResponseParams)
      throws IllegalArgumentException, PersistenceException {
    // Must be of type StudentPersonalType
    if (data instanceof StudentPersonalCollectionType) {
      logger.debug(
          "Create students (Bulk Operation) for "
              + getZoneAndContext(zone, context)
              + " and RequestMetadata = "
              + metadata);
      StudentPersonalCollectionType students = (StudentPersonalCollectionType) data;
      ArrayList<CreateOperationStatus> opStatus = new ArrayList<CreateOperationStatus>();
      int i = 0;
      for (StudentPersonalType student : students.getStudentPersonal()) {
        if ((i % 3) == 0) {
          // Set advisoryID the same as resourceID.
          opStatus.add(
              new CreateOperationStatus(
                  student.getRefId(),
                  student.getRefId(),
                  404,
                  new ErrorDetails(400, "Data not good.")));
        } else {
          if (useAdvisory) {
            // Advisory refId was used. Set resourceId and advisoryId to the same
            opStatus.add(new CreateOperationStatus(student.getRefId(), student.getRefId(), 201));
          } else {
            // Create a new refId (resourceID) but we must also report back the original RefId as
            // the advisory if it was available.
            opStatus.add(
                new CreateOperationStatus(
                    UUIDGenerator.getSIF2GUIDUpperCase(), student.getRefId(), 201));
          }
        }
        i++;
      }

      return opStatus;
    } else {
      throw new IllegalArgumentException(
          "Expected Object Type  = StudentCollectionType. Received Object Type = "
              + data.getClass().getSimpleName());
    }
  }
  /* (non-Javadoc)
   * @see sif3.common.interfaces.Provider#createSingle(java.lang.Object, sif3.common.model.SIFZone, sif3.common.model.SIFContext)
   */
  @Override
  public Object createSingle(
      Object data,
      boolean useAdvisory,
      SIFZone zone,
      SIFContext context,
      RequestMetadata metadata,
      ResponseParameters customResponseParams)
      throws IllegalArgumentException, PersistenceException {
    logger.debug(
        "Create Single Student for "
            + getZoneAndContext(zone, context)
            + " and RequestMetadata = "
            + metadata);

    //    	return null; // test return null value

    // Must be of type StudentPersonalType
    if (data instanceof StudentPersonalType) {
      StudentPersonalType student = (StudentPersonalType) data;
      if (StringUtils.isEmpty(student.getRefId())) {
        // In future this should be a UUID instead of a GUID
        if (!useAdvisory) {
          // Create new UUID because the advisory shall not be used.
          student.setRefId(UUIDGenerator.getSIF2GUIDUpperCase());
        }
        // else leave student UUID untouched.
      }

      // In the real implementation we would call a BL method here to create the Student.
      return student;
    } else {
      throw new IllegalArgumentException(
          "Expected Object Type  = StudentPersonalType. Received Object Type = "
              + data.getClass().getSimpleName());
    }
  }