Search in sources :

Example 1 with IFileManager

use of com.att.aro.core.fileio.IFileManager in project VideoOptimzer by attdevsupport.

the class Validator method validate.

public ErrorCode validate(Commands cmd, ApplicationContext context) {
    if (cmd.getAnalyze() != null) {
        if (cmd.getFormat().equals("json") && cmd.getFormat().equals("html")) {
            return ErrorCodeRegistry.getUnsupportedFormat();
        }
        if (cmd.getOutput() == null) {
            return ErrorCodeRegistry.getOutputRequired();
        }
        IFileManager filemg = context.getBean(IFileManager.class);
        if (filemg.fileExist(cmd.getOutput())) {
            if ("yes".equals(cmd.getOverwrite())) {
                filemg.deleteFile(cmd.getOutput());
            } else {
                return ErrorCodeRegistry.getFileExist();
            }
        }
    } else {
        if (cmd.getStartcollector() != null) {
            String colname = cmd.getStartcollector();
            if (!"rooted_android".equals(colname) && !"vpn_android".equals(colname) && !"ios".equals(colname)) {
                return ErrorCodeRegistry.getUnsupportedCollector();
            }
            if (cmd.getOutput() == null) {
                return ErrorCodeRegistry.getOutputRequired();
            }
        }
        if (cmd.getVideo() != null && !cmd.getVideo().equals("yes") && !cmd.getVideo().equals("no") && !cmd.getVideo().equals("hd") && !cmd.getVideo().equals("sd") && !cmd.getVideo().equals("slow")) {
            return ErrorCodeRegistry.getInvalidVideoOption();
        }
        ErrorCode uplinkErrorCode = validateUplink(cmd);
        if (uplinkErrorCode != null) {
            return uplinkErrorCode;
        }
        ErrorCode downlinkErrorCode = validateDownlink(cmd);
        if (downlinkErrorCode != null) {
            return downlinkErrorCode;
        }
    }
    return null;
}
Also used : ErrorCode(com.att.aro.core.pojo.ErrorCode) IFileManager(com.att.aro.core.fileio.IFileManager)

Example 2 with IFileManager

use of com.att.aro.core.fileio.IFileManager in project VideoOptimzer by attdevsupport.

the class CpuActivityReaderImplTest method readData_IOException.

@Test
public void readData_IOException() throws IOException {
    reader = (CpuActivityReaderImpl) context.getBean(ICpuActivityReader.class);
    IFileManager filereader = Mockito.mock(IFileManager.class);
    Mockito.when(filereader.fileExist(Mockito.anyString())).thenReturn(true);
    Mockito.when(filereader.readAllLine(Mockito.anyString())).thenThrow(new IOException("test exception"));
    reader.setFileReader(filereader);
    CpuActivityList info = reader.readData("/", 0.0);
    assertTrue(info.getCpuActivities().size() == 0);
}
Also used : CpuActivityList(com.att.aro.core.peripheral.pojo.CpuActivityList) IOException(java.io.IOException) IFileManager(com.att.aro.core.fileio.IFileManager) Test(org.junit.Test) BaseTest(com.att.aro.core.BaseTest)

Example 3 with IFileManager

use of com.att.aro.core.fileio.IFileManager in project VideoOptimzer by attdevsupport.

the class LoadManifestDialog method loadManifest.

/**
 * Copy a file, files or a folder of files into tracepath/downloads/ Will traverse folders within a folder
 */
protected void loadManifest(AnalysisFilter analysisfilter) {
    if (aroView.getTracePath() != null) {
        // Open filechooser
        JFileChooser fileChooser = new JFileChooser(aroView.getTracePath());
        fileChooser.setMultiSelectionEnabled(true);
        fileChooser.addChoosableFileFilter(new FileNameExtensionFilter("mpd, m3u8 or json", "mpd", "m3u8", "json"));
        fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
        fileChooser.setAcceptAllFileFilterUsed(false);
        int result = fileChooser.showOpenDialog(this);
        if (result == JFileChooser.APPROVE_OPTION) {
            if (checkBoxCSI.isSelected() && analysisfilter != null) {
                String folderNameForCSIStuff = aroView.getTracePath() + File.separator + "CSI";
                String expectedManifestFileName = folderNameForCSIStuff + File.separator + fileChooser.getSelectedFile().getName();
                File expectedManifestFile = new File(expectedManifestFileName);
                try {
                    if (!fileChooser.getSelectedFile().getPath().equals(expectedManifestFileName) && !expectedManifestFile.exists()) {
                        IFileManager fileManager = new FileManagerImpl();
                        if (fileManager.directoryExistAndNotEmpty(expectedManifestFile.getParentFile().getPath())) {
                            if (folderExistsDialog() == JOptionPane.YES_OPTION) {
                                FileUtils.deleteDirectory(expectedManifestFile.getParentFile());
                            }
                        }
                        if (!Files.exists(expectedManifestFile.getParentFile().toPath())) {
                            Files.createDirectory(expectedManifestFile.getParentFile().toPath());
                        }
                        if (fileChooser.getSelectedFile().getParent().equals(aroView.getTracePath())) {
                            Files.move(fileChooser.getSelectedFile().toPath(), expectedManifestFile.toPath());
                        } else {
                            Files.copy(fileChooser.getSelectedFile().toPath(), expectedManifestFile.toPath());
                        }
                    }
                } catch (IOException ioe) {
                    expectedManifestFileName = fileChooser.getSelectedFile().getPath();
                }
                analysisfilter.setCSI(true);
                analysisfilter.setManifestFilePath(expectedManifestFileName);
                ((MainFrame) aroView).updateFilter(analysisfilter);
            } else {
                // save selected file/files inside downloads folder
                fileChooser.getSelectedFile().getPath();
                String downloadsPath = aroView.getTracePath() + Util.FILE_SEPARATOR + "downloads";
                try {
                    File[] files = fileChooser.getSelectedFiles();
                    if (!files[0].toString().equals(downloadsPath)) {
                        // expand out of folder
                        if (fileChooser.getSelectedFile().isDirectory()) {
                            files = files[0].listFiles();
                        }
                        if (null == files) {
                            return;
                        }
                        for (File file : files) {
                            if (file.isFile()) {
                                FileCopyUtils.copy(file, new File(downloadsPath, file.getName()));
                            }
                        }
                    } else {
                        LOG.error("user error :Chose downloads folder, will ignore");
                    }
                } catch (IOException e1) {
                    LOG.error("IOException :" + e1.getMessage());
                }
                // refresh analyzer
                aroView.updateTracePath(new File(aroView.getTracePath()));
            }
        }
    }
}
Also used : JFileChooser(javax.swing.JFileChooser) IOException(java.io.IOException) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) File(java.io.File) FileManagerImpl(com.att.aro.core.fileio.impl.FileManagerImpl) MainFrame(com.att.aro.ui.view.MainFrame) IFileManager(com.att.aro.core.fileio.IFileManager)

Example 4 with IFileManager

use of com.att.aro.core.fileio.IFileManager in project VideoOptimzer by attdevsupport.

the class FileManagerTest method findFiles.

@Test
public void findFiles() throws Exception {
    String[] foundFiles;
    VideoStreamConstructor videoStreamConstructor = context.getBean(VideoStreamConstructor.class);
    IFileManager filemanager = context.getBean(IFileManager.class);
    File tempFolder = Files.createTempDir();
    filemanager.createFile(tempFolder.toString(), "file1");
    String pathName1 = filemanager.createFile(tempFolder.toString(), "file1").toString();
    String pathName1exten = filemanager.createFile(tempFolder.toString(), "file1.xyz").toString();
    byte[] content = "dummy data".getBytes();
    videoStreamConstructor.savePayload(content, pathName1);
    videoStreamConstructor.savePayload(content, pathName1exten);
    foundFiles = fileManager.findFiles(tempFolder.toString(), ".xyz");
    assertThat(foundFiles).hasSize(1);
    assertThat(foundFiles).contains("file1.xyz");
    foundFiles = fileManager.findFiles(tempFolder.toString(), "child.xyz");
    assertThat(foundFiles).isEmpty();
    foundFiles = fileManager.findFiles(tempFolder.toString(), ".sh");
    assertThat(foundFiles).isEmpty();
    filemanager.directoryDeleteInnerFiles(tempFolder.toString());
    filemanager.deleteFile(tempFolder.toString());
}
Also used : File(java.io.File) VideoStreamConstructor(com.att.aro.core.packetanalysis.impl.VideoStreamConstructor) IFileManager(com.att.aro.core.fileio.IFileManager) BaseTest(com.att.aro.core.BaseTest) Test(org.junit.Test)

Example 5 with IFileManager

use of com.att.aro.core.fileio.IFileManager in project VideoOptimzer by attdevsupport.

the class AROController method startCollector.

/**
 * Start the collector on device
 *
 * @param deviceId
 * @param traceFolderName
 * @param videoOption
 * @param secure
 */
public StatusResult startCollector(IAroDevice device, String traceFolderName, Hashtable<String, Object> extraParams) {
    StatusResult result = null;
    LOG.info("starting collector:" + traceFolderName + " " + extraParams);
    getAvailableCollectors();
    collector = device.getCollector();
    if (collector == null) {
        collector = loadCollector(device);
    }
    traceFolderPath = getTraceFolderPath(device, traceFolderName);
    IFileManager fileManager = context.getBean(IFileManager.class);
    if (!fileManager.directoryExistAndNotEmpty(traceFolderPath)) {
        result = collector.startCollector(false, traceFolderPath, null, true, device.getId(), extraParams, collector.getPassword());
        traceStartTime = new Date();
        if (result.isSuccess()) {
            LOG.info("Result : traffic capture launched successfully");
            traceDuration = 0;
        } else {
            LOG.error("Result trace success:" + result.isSuccess() + ", Name :" + result.getError().getName() + ", Description :" + result.getError().getDescription());
            LOG.error("device logcat:");
        }
    } else {
        LOG.info("Illegal path:" + traceFolderPath);
        result = new StatusResult();
        result.setError(ErrorCodeRegistry.getTraceFolderNotFound());
        return result;
    }
    return result;
}
Also used : StatusResult(com.att.aro.core.datacollector.pojo.StatusResult) Date(java.util.Date) IFileManager(com.att.aro.core.fileio.IFileManager)

Aggregations

IFileManager (com.att.aro.core.fileio.IFileManager)11 BaseTest (com.att.aro.core.BaseTest)5 Test (org.junit.Test)5 File (java.io.File)4 IOException (java.io.IOException)3 Date (java.util.Date)3 StatusResult (com.att.aro.core.datacollector.pojo.StatusResult)2 AlarmAnalysisInfo (com.att.aro.core.peripheral.pojo.AlarmAnalysisInfo)2 AlarmAnalysisResult (com.att.aro.core.peripheral.pojo.AlarmAnalysisResult)2 CpuActivityList (com.att.aro.core.peripheral.pojo.CpuActivityList)2 MainFrame (com.att.aro.ui.view.MainFrame)2 OutSave (com.att.aro.console.printstreamutils.OutSave)1 IDataCollector (com.att.aro.core.datacollector.IDataCollector)1 IDataCollectorManager (com.att.aro.core.datacollector.IDataCollectorManager)1 FileManagerImpl (com.att.aro.core.fileio.impl.FileManagerImpl)1 VideoStreamConstructor (com.att.aro.core.packetanalysis.impl.VideoStreamConstructor)1 AttenuatorModel (com.att.aro.core.peripheral.pojo.AttenuatorModel)1 AROTraceData (com.att.aro.core.pojo.AROTraceData)1 ErrorCode (com.att.aro.core.pojo.ErrorCode)1 Orientation (com.att.aro.core.video.pojo.Orientation)1