Changeset 4382


Ignore:
Timestamp:
Aug 7, 2008, 9:02:13 AM (14 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #1069: New mode for Import reporters to reporterlist - Add existing without risk of updating or creating

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/plugins/core/net/sf/basedb/plugins/ReporterFlatFileImporter.java

    r4356 r4382  
    393393  private ReporterList reporterList;
    394394  private boolean updateExisting;
     395  private boolean createMissing;
    395396  private boolean deleteMode;
    396397  private int numInserted;
     
    422423    reporterType = (ReporterType)configuration.getValue("reporterType");
    423424    reporterList = (ReporterList)job.getValue("reporterList");
     425    String mode = (String)job.getValue("mode");
    424426    if (reporterList != null)
    425427    {
     
    427429      deferred = new HashMap<String, Float>();
    428430      numAddedToList = 0;
    429     }
    430     String mode = (String)job.getValue("mode");
    431     updateExisting = "update".equals(mode);
    432     deleteMode = "delete".equals(mode);
     431      deleteMode = "remove".equals(mode);
     432      updateExisting = false;
     433      createMissing = false;
     434    }
     435    else
     436    {
     437      updateExisting = "update".equals(mode);
     438      createMissing = updateExisting || "create".equals(mode);
     439      deleteMode = "delete".equals(mode);
     440    }
    433441    this.ffp = ffp;
    434442    this.numberFormat = ffp.getDefaultNumberFormat();
     
    592600        {
    593601          // It wasn't in the database either, create a new reporter
    594           reporter = Reporter.getNew(externalId);
     602          numNotFound++;
     603          if (createMissing)
     604          {
     605            reporter = Reporter.getNew(externalId);
     606          }
    595607        }
    596608      }
     
    666678  {
    667679    String msg;
    668     if (deleteMode)
    669     {
    670       msg = numDeleted + " deleted reporter(s)";
    671       if (numUsed > 0) msg += "; " + numUsed + " reporter(s) are used and could not be deleted";
     680    if (reporterList != null)
     681    {
     682      if (deleteMode)
     683      {
     684        msg = numDeleted + " reporter(s) removed from list";
     685      }
     686      else
     687      {
     688        msg = numAddedToList + " reporter(s) added to list";
     689      }
    672690      if (numNotFound > 0) msg += "; " + numNotFound + " reporter(s) ignored because they didn't exist";
    673691    }
    674692    else
    675693    {
    676       msg = numInserted + " new reporter(s)";
    677       if (numUpdated > 0) msg += "; " + numUpdated + " updated reporter(s)";
    678       if (numExists > 0) msg += "; " + numExists + " reporter(s) skipped (already existed)"; 
    679       if (reporterList != null) msg += "; " + numAddedToList + " reporter(s) added to list";
     694      if (deleteMode)
     695      {
     696        msg = numDeleted + " deleted reporter(s)";
     697        if (numUsed > 0) msg += "; " + numUsed + " reporter(s) are used and could not be deleted";
     698        if (numNotFound > 0) msg += "; " + numNotFound + " reporter(s) ignored because they didn't exist";
     699      }
     700      else
     701      {
     702        msg = numInserted + " new reporter(s)";
     703        if (numUpdated > 0) msg += "; " + numUpdated + " updated reporter(s)";
     704        if (numExists > 0)
     705        {
     706          msg += "; " + numExists + " reporter(s) skipped (already existed)";
     707        }
     708      }
    680709    }
    681710    if (skippedLines > 0) msg += "; " + skippedLines + " line(s) skipped due to errors";
     
    721750      // RequestInformation for CONFIGURE_JOB
    722751      List<PluginParameter<?>> parameters = new ArrayList<PluginParameter<?>>();
    723       if (context != null &&
    724         (context.getItem() == Item.REPORTERLIST || context.getItem() == Item.REPORTERSCORE))
     752      boolean reporterListContext = context != null &&
     753      (context.getItem() == Item.REPORTERLIST || context.getItem() == Item.REPORTERSCORE);
     754     
     755      if (reporterListContext)
    725756      {
    726757        ItemParameterType<ReporterList> reporterListType = new ItemParameterType<ReporterList>(ReporterList.class, null, true, 1, null);
     
    734765      parameters.add(fileParameter);
    735766     
     767      boolean deletePermission = sc.hasPermission(Permission.DELETE, Item.REPORTER);
     768      boolean createPermission = sc.hasPermission(Permission.CREATE, Item.REPORTER);
     769      boolean writePermission = sc.hasPermission(Permission.WRITE, Item.REPORTER);
     770     
    736771      List<String> allowedModes = new ArrayList<String>();
    737       String defaultMode = "update";
    738       allowedModes.add("create");
    739       allowedModes.add("update");
    740       if (context.getItem() != Item.REPORTER || sc.hasPermission(Permission.DELETE, Item.REPORTER))
    741       {
    742         allowedModes.add("delete");
     772      String modeDescription = "";
     773      String defaultMode = null;
     774      if (reporterListContext)
     775      {
     776        allowedModes.add("add");
     777        allowedModes.add("remove");
     778        defaultMode = "add";
     779        modeDescription =
     780          "Select the operating mode of the plug-in. When adding/removing to/from a " +
     781          "reporter list, reporters will not be created or updated.\n\n" +
     782          "add = Add reporters to the reporter list\n" +
     783          "remove = Remove reporter from the reporter list";
     784      }
     785      else
     786      {
     787        modeDescription = "Select the operating mode of the plug-in.\n\n";
     788        if (createPermission)
     789        {
     790          allowedModes.add("create");
     791          modeDescription += "create = Only create missing reporters; existing ones are not updated\n";
     792        }
     793        if (writePermission)
     794        {
     795          allowedModes.add("update");
     796          defaultMode = "update";
     797          modeDescription += "update = Update existing reporters and create missing ones\n";
     798        }
     799        if (deletePermission)
     800        {
     801          allowedModes.add("delete");
     802          modeDescription += "delete = Delete existing reporters\n";
     803        }
    743804      }
    744805      StringParameterType modeType = new StringParameterType(255, defaultMode, false, 1, 0, 0, allowedModes);
     
    746807          "mode",
    747808          "Mode",
    748           "Select the operating mode of the plug-in. Depending on permissions not all modes " +
    749           "may be available\n\n" +
    750           "create = Only create missing reporters; existing ones are not updated\n" +
    751           "update = Update existing reporters and create missing ones\n" +
    752           "delete = Delete existing reporters",
     809          modeDescription,
    753810          modeType
    754811          );
     
    766823      parameters.add(numberFormatErrorParameter);
    767824      parameters.add(numberOutOfRangeErrorParameter);
    768       parameters.add(reporterIsUsedErrorParameter);
    769      
     825      if (!reporterListContext)
     826      {
     827        parameters.add(reporterIsUsedErrorParameter);
     828      }
    770829      configureJob = new RequestInformation
    771830      (
Note: See TracChangeset for help on using the changeset viewer.