Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package utils;
- import com.filenet.api.core.Document;
- import ru.fns.common.helper.FileHelper;
- import ru.fns.common.util.Timer;
- import ru.fns.filenet.api.FileNet;
- import ru.fns.filenet.api.ObjectStore;
- import ru.fns.filenet.api.util.ConnectParams;
- import java.io.File;
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.List;
- /**
- * ========== ItCorp v. 1.0 class library ==========
- * <p/>
- * http://www.it.ru/
- * <p/>
- * © Copyright 1990-2013, by ItCorp.
- * <p/>
- * ========== ChangeAttributes.java ==========
- * <p/>
- * $Revision: $<br/>
- * $Author: $<br/>
- * $HeadURL: $<br/>
- * $Id: $
- * <p/>
- * 30.09.15 22:28: Original version (ASTarasov)<br/>
- */
- public class FNS_5763_FindingUnuseFiles {
- public static void main(String[] args) throws IOException {
- if (args.length < 6) throw new IllegalArgumentException("FUCK!");
- //\\dpc.tax.nalog.ru\ROOT\GRs\gr216\TRANSPORT_FCOD\CPS\processing\N7700\
- //\\dpc.tax.nalog.ru\ROOT\GRs\gr216\TRANSPORT_FCOD\CPS\INBOX\MANUAL_N7700
- final String transportCPSFolder = args[0];
- final String ceUri = args[1];
- final String user = args[2];
- final String pass = args[3];
- final String os = args[4];
- final String type = args[5];
- if (!new File(transportCPSFolder).exists()) {
- System.err.println("Failed to execute, cuz: transportCPSFolder is not exists");
- return;
- }
- final File processingFolder = new File(transportCPSFolder, "processing");
- final File inboxFolder = new File(transportCPSFolder, "INBOX");
- System.out.println("Trying to scan processingFolder: '" + processingFolder.getAbsolutePath() + "'");
- Timer t = Timer.registerStart();
- final File[] cpsFolders = processingFolder.listFiles();
- long totalTime = t.registerStop();
- if (cpsFolders == null) {
- System.err.println("Failed to scan processing folder...");
- return;
- }
- System.out.println("We've found '" + cpsFolders.length + "' cps folders.. It took '" + totalTime + "'ms");
- for (final File cpsFolder : cpsFolders) {
- final String cps = cpsFolder.getName();
- final File manualFolder = new File(inboxFolder, "MANUAL_" + cps);
- final List<File> filesToBeMoved = new ArrayList<File>();
- System.out.println("Will be work by '" + cps + "' cps folder: '" + cpsFolder.getAbsolutePath() + "'");
- t = Timer.registerStart();
- System.out.println("Trying to scan cpsFolder: '" + cpsFolder.getAbsolutePath() + "'");
- Timer ct = Timer.registerStart();
- final File[] uuidFolders = cpsFolder.listFiles();
- if (uuidFolders == null) {
- System.err.println("Failed to scan cps folder...");
- return;
- }
- totalTime = ct.registerStop();
- System.out.println("We've found '" + uuidFolders.length + "' uuid folders.. It took '" + totalTime + "'ms");
- ConnectParams params = new ConnectParams(ceUri, user, pass, os, type);
- try {
- FileNet.connect(params, false, new FileNet.FileNetClosure() {
- @Override
- public void closure(FileNet fileNet) throws Exception {
- fileNet.useObjectStore(os, new FileNet.ObjectStoreClosure() {
- @Override
- public void closure(ObjectStore objectStore) throws Exception {
- int processed = 0;
- for (File uuidFolder : uuidFolders) {
- processed++;
- if (!uuidFolder.isDirectory()) continue;
- File[] files = uuidFolder.listFiles();
- if (files == null) continue;
- if (files.length == 0) {
- System.out.println("One of uuid folder: '" + uuidFolder.getAbsolutePath() + "' is an empty. We'll remove it.");
- FileHelper.deleteFileSilent(uuidFolder);
- continue;
- }
- for (File file : files) {
- String fileName = file.getName();
- if (!fileName.startsWith("16")) continue;
- List<Document> documents = objectStore.searchObjects("select id from TechInboxDocument where urlPath LIKE '%" + fileName + "'");
- if (documents.isEmpty()) {
- //повторная проверка на доступность, на случай если джоб отработал и уже удалил файлик.
- if (file.exists()) {
- filesToBeMoved.add(file);
- System.out.println("#" + processed + "/" + uuidFolders.length + "\tWe've found missing file: '" + file.getAbsolutePath() + "'. It will be moved to manual folder");
- }
- }
- }
- }
- }
- });
- }
- });
- } catch (Exception e) {
- e.printStackTrace();
- }
- if (!filesToBeMoved.isEmpty()) {
- System.out.println("Trying to move '" + filesToBeMoved.size() + "' files to manual folder: '" + manualFolder.getAbsolutePath() + "'");
- Timer mt = Timer.registerStart();
- for (File fileToBeMoved : filesToBeMoved) {
- File parent = fileToBeMoved.getParentFile();
- File newFilePath = new File(manualFolder, fileToBeMoved.getName());
- FileHelper.copyFile(fileToBeMoved, newFilePath);
- FileHelper.deleteFileSilent(fileToBeMoved);
- System.out.println("File: '" + fileToBeMoved.getAbsolutePath() + "' has moved to '" + newFilePath.getAbsolutePath() + "'");
- if (parent.list().length == 0) {
- FileHelper.deleteFileSilent(parent);
- System.out.println("Removed folder: '" + parent.getAbsolutePath() + "' also");
- }
- }
- totalTime = mt.registerStop();
- System.out.println("File moving took '" + totalTime + "'ms");
- }
- totalTime = t.registerStop();
- System.out.println("CPS folder has been processed. It took '" + totalTime + "'ms");
- }
- System.out.println("DONE!");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement