/**
  * Executes this action.
  *
  * @param parent the parent window
  */
 public void execute(Window parent) {
   File f = new File(fileName);
   try {
     SignatureFileInfo info = signatureManager.upload(type, f, useAsDefault);
     String message =
         String.format("Signature file %s has been uploaded", info.getFile().getName());
     JOptionPane.showMessageDialog(
         parent, message, "Signature file uploaded", JOptionPane.INFORMATION_MESSAGE);
   } catch (SignatureFileException e) {
     JOptionPane.showMessageDialog(
         parent, e.getMessage(), "Error uploading signature file", JOptionPane.ERROR_MESSAGE);
   }
 }
  /** {@inheritDoc} */
  @Override
  protected Map<SignatureType, SignatureFileInfo> doInBackground()
      throws SignatureManagerException {
    Map<SignatureType, SignatureFileInfo> downloaded =
        new HashMap<SignatureType, SignatureFileInfo>();

    for (SignatureFileInfo update : updates) {
      if (!update.hasError()) {
        downloaded.put(update.getType(), signatureManager.downloadLatest(update.getType()));
      }
    }

    return downloaded;
  }
  /** @throws CommandExecutionException */
  private void updateDefaultVersion(String key) throws CommandExecutionException {
    final PropertiesConfiguration properties = globalConfig.getProperties();
    properties.setProperty(mapping.get(type).getName(), key);
    try {
      properties.save();
      SignatureFileInfo sigFileInfo = signatureManager.getDefaultSignatures().get(type);
      printWriter.println(
          I18N.getResource(
              I18N.CONFIGURE_SIGNATURE_FILE_VERSION_SUCCESS,
              sigFileInfo.getVersion(),
              sigFileInfo.getFile().getName()));

    } catch (ConfigurationException e) {
      throw new CommandExecutionException(e);
    } catch (SignatureFileException e) {
      throw new CommandExecutionException(e);
    }
  };
Ejemplo n.º 4
0
  @Test
  public void testRunProfileAndSaveToDefaultExtensionWhenNoExtensionSupplied() throws Exception {
    command.setDestination("test");
    command.setResources(
        new String[] {
          "test1.txt", "test2.txt",
        });

    SignatureFileInfo sig = mock(SignatureFileInfo.class);
    Map<SignatureType, SignatureFileInfo> sigs = new HashMap<SignatureType, SignatureFileInfo>();
    sigs.put(SignatureType.BINARY, sig);

    when(signatureManager.getDefaultSignatures()).thenReturn(sigs);

    ProfileInstance profileInstance = mock(ProfileInstance.class);
    when(profileInstance.getUuid()).thenReturn("abcde");
    when(profileManager.createProfile(sigs)).thenReturn(profileInstance);

    Future future = mock(Future.class);
    when(profileManager.start("abcde")).thenReturn(future);

    FileProfileResource resource1 = new FileProfileResource(new File("test1.txt"));
    FileProfileResource resource2 = new FileProfileResource(new File("test2.txt"));

    when(locationResolver.getResource("test1.txt", false)).thenReturn(resource1);
    when(locationResolver.getResource("test2.txt", false)).thenReturn(resource2);

    command.execute();

    verify(profileInstance).addResource(resource1);
    verify(profileInstance).addResource(resource2);
    verify(profileManager).createProfile(sigs);
    verify(profileManager).start("abcde");
    verify(future).get();
    verify(profileManager).save(eq("abcde"), eq(new File("test")), any(ProgressObserver.class));
    verify(profileManager).closeProfile("abcde");
  }
  /** {@inheritDoc} */
  @Override
  public void execute() throws CommandExecutionException {

    boolean validVersion = false;
    Map<SignatureType, SortedMap<String, SignatureFileInfo>> sigFileInfos =
        signatureManager.getAvailableSignatureFiles();

    Map<String, SignatureFileInfo> sigFileInfoForType = sigFileInfos.get(type);

    for (Map.Entry<String, SignatureFileInfo> entry : sigFileInfoForType.entrySet()) {
      String key = entry.getKey();
      SignatureFileInfo info = entry.getValue();
      if (info.getVersion() == signatureFileVersion) {
        validVersion = true;
        updateDefaultVersion(key);
        break;
      }
    }

    if (!validVersion) {
      throw new CommandExecutionException(
          I18N.getResource(I18N.CONFIGURE_SIGNATURE_FILE_VERSION_INVALID, signatureFileVersion));
    }
  }