Skip to main content
summaryrefslogtreecommitdiffstats
blob: 83ef83e79acbd43c92c7ff8a78e93e9f25dd95d0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*******************************************************************************
 * Copyright (c) 2004, 2007 Boeing.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Boeing - initial API and implementation
 *******************************************************************************/
package org.eclipse.osee.framework.server.admin.branch;

import java.io.File;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.osee.framework.core.exception.OseeArgumentException;
import org.eclipse.osee.framework.jdk.core.util.Lib;
import org.eclipse.osee.framework.resource.management.util.ResourceLocator;
import org.eclipse.osee.framework.server.admin.BaseServerCommand;
import org.eclipse.osee.framework.server.admin.internal.Activator;

/**
 * @author Roberto E. Escobar
 */
public class ExchangeIntegrityWorker extends BaseServerCommand {

   protected ExchangeIntegrityWorker() {
      super("Verify Exchange File");
   }

   private boolean isValidArg(String arg) {
      return arg != null && arg.length() > 0;
   }

   @Override
   protected void doCommandWork(IProgressMonitor monitor) throws Exception {
      String arg = null;
      int count = 0;
      List<File> importFiles = new ArrayList<File>();
      do {
         arg = getCommandInterpreter().nextArgument();
         if (isValidArg(arg)) {
            if (count == 0 && !arg.startsWith("-")) {
               importFiles.add(new File(arg));
            }
            count++;
         }
      } while (isValidArg(arg));

      if (importFiles.isEmpty()) {
         throw new IllegalArgumentException("File to check was not specified");
      }

      for (File file : importFiles) {
         if (file == null || !file.exists() || !file.canRead()) {
            throw new OseeArgumentException("File was not accessible: [%s]", file);
         } else if (file.isFile() && !Lib.isCompressed(file)) {
            throw new OseeArgumentException("Invalid File: [%s]", file);
         }
      }

      for (File fileToImport : importFiles) {
         URI uri = new URI("exchange://" + fileToImport.toURI().toASCIIString());
         Activator.getInstance().getBranchExchange().checkIntegrity(new ResourceLocator(uri));
      }
   }
}

Back to the top