Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
5.1 kB
2
Indexable
Never
private static void setDBWrapperStrategy(List<SObject> sObjectList, DatabaseResultWrapper databaseResultWrapper, Error[] wrapperErrors){

    if (wrapperErrors.isEmpty()) {
      setDatabaseResultWrapper(databaseResultWrapper, GUS_Constants.FINISHED_SUCCESSFULLY, wrapperErrors, String.valueOf(sObjectList.size()) + ' ' + Label.GUS_successfullyUpdated);

      if (sObjectList.size() == 1) {
        setDatabaseResultWrapper(databaseResultWrapper, '', wrapperErrors, ' ' + Label.GUS_SingleRecordUpdatedSuccessfully);
      }
    } else {
      Integer successfullyUpdated = sObjectList.size() - wrapperErrors.size();

      if(successfullyUpdated == 1 && wrapperErrors.size() == 1){
        setDatabaseResultWrapper(databaseResultWrapper, GUS_Constants.FINISHED_PARTIALLY_SUCCESSFUL, wrapperErrors,
                String.valueOf(successfullyUpdated) + ' ' + Label.GUS_SingleRecordUpdatedSuccessfully + '. ' + String.valueOf(wrapperErrors.size()) + ' ' + Label.GUS_SingleRecordNotUpdated);

      } else if(successfullyUpdated == 1 && wrapperErrors.size() > 1 && wrapperErrors.size() < 5) {
        setDatabaseResultWrapper(databaseResultWrapper, GUS_Constants.FINISHED_PARTIALLY_SUCCESSFUL, wrapperErrors,
                String.valueOf(successfullyUpdated) + ' ' + Label.GUS_SingleRecordUpdatedSuccessfully + '. ' + String.valueOf(wrapperErrors.size()) + ' ' + Label.GUS_RecordsWithErrors);
      } else if(successfullyUpdated == 1 && wrapperErrors.size() > 1 && wrapperErrors.size() >= 5) {
        setDatabaseResultWrapper(databaseResultWrapper, GUS_Constants.FINISHED_PARTIALLY_SUCCESSFUL, wrapperErrors,
        String.valueOf(successfullyUpdated) + ' ' + Label.GUS_SingleRecordUpdatedSuccessfully + '. ' + String.valueOf(wrapperErrors.size()) + ' ' + Label.GUS_MoreRecordsWithErrors);
      } else if(successfullyUpdated > 1 && successfullyUpdated < 5 && wrapperErrors.size() == 1){
        setDatabaseResultWrapper(databaseResultWrapper, GUS_Constants.FINISHED_PARTIALLY_SUCCESSFUL, wrapperErrors,
                String.valueOf(successfullyUpdated) + ' ' + Label.GUS_successfullyUpdated + '. ' + String.valueOf(wrapperErrors.size()) + ' ' + Label.GUS_SingleRecordNotUpdated);
      } else if(successfullyUpdated >= 5 && wrapperErrors.size() == 1){
        setDatabaseResultWrapper(databaseResultWrapper, GUS_Constants.FINISHED_PARTIALLY_SUCCESSFUL, wrapperErrors,
                String.valueOf(successfullyUpdated) + ' ' + Label.GUS_MoreSuccessfullyUpdated + '. ' + String.valueOf(wrapperErrors.size()) + ' ' + Label.GUS_SingleRecordNotUpdated);
      } else if(successfullyUpdated >= 5 && wrapperErrors.size() >= 5){
        setDatabaseResultWrapper(databaseResultWrapper, GUS_Constants.FINISHED_PARTIALLY_SUCCESSFUL, wrapperErrors,
                String.valueOf(successfullyUpdated) + ' ' + Label.GUS_MoreSuccessfullyUpdated + '. ' + String.valueOf(wrapperErrors.size()) + ' ' + Label.GUS_MoreRecordsWithErrors);
      } else if(successfullyUpdated > 1 && successfullyUpdated < 5 && wrapperErrors.size() >= 5){
        setDatabaseResultWrapper(databaseResultWrapper, GUS_Constants.FINISHED_PARTIALLY_SUCCESSFUL, wrapperErrors,
                String.valueOf(successfullyUpdated) + ' ' + Label.GUS_successfullyUpdated + '. ' + String.valueOf(wrapperErrors.size()) + ' ' + Label.GUS_MoreRecordsWithErrors);
      } else if(successfullyUpdated > 1 && successfullyUpdated < 5 && wrapperErrors.size() < 5){
        setDatabaseResultWrapper(databaseResultWrapper, GUS_Constants.FINISHED_PARTIALLY_SUCCESSFUL, wrapperErrors,
                String.valueOf(successfullyUpdated) + ' ' + Label.GUS_successfullyUpdated + '. ' + String.valueOf(wrapperErrors.size()) + ' ' + Label.GUS_RecordsWithErrors);
      } else if(successfullyUpdated >= 5 && wrapperErrors.size() < 5){
        setDatabaseResultWrapper(databaseResultWrapper, GUS_Constants.FINISHED_PARTIALLY_SUCCESSFUL, wrapperErrors,
                String.valueOf(successfullyUpdated) + ' ' + Label.GUS_MoreSuccessfullyUpdated + '. ' + String.valueOf(wrapperErrors.size()) + ' ' + Label.GUS_RecordsWithErrors);
      } else {
        setDatabaseResultWrapper(databaseResultWrapper, GUS_Constants.FINISHED_PARTIALLY_SUCCESSFUL, wrapperErrors,
                String.valueOf(successfullyUpdated) + ' ' + Label.GUS_successfullyUpdated + '. ' + String.valueOf(wrapperErrors.size()) + ' ' + Label.GUS_RecordsWithErrors);
      }


      if (sObjectList.size() == 1) {
        setDatabaseResultWrapper(databaseResultWrapper, '', wrapperErrors, ' ' + Label.GUS_SingleRecordNotUpdated);
      }

      if (sObjectList.size() == wrapperErrors.size() && wrapperErrors.size() >= 5) {
        setDatabaseResultWrapper(databaseResultWrapper, GUS_Constants.FINISHED_WITH_ERRORS, wrapperErrors, String.valueOf(wrapperErrors.size()) + ' ' + Label.GUS_MoreRecordsWithErrors);
      }

      if (sObjectList.size() == wrapperErrors.size() && wrapperErrors.size() < 5) {
        setDatabaseResultWrapper(databaseResultWrapper, GUS_Constants.FINISHED_WITH_ERRORS, wrapperErrors, String.valueOf(wrapperErrors.size()) + ' ' + Label.GUS_RecordsWithErrors);
      }

    }

  }