public Boolean dataSourceExport(DataSourceUI dataSourceUI) throws ServerSideException { try { RepoxManagerDefault repoxManagerDefault = (RepoxManagerDefault) ConfigSingleton.getRepoxContextUtil().getRepoxManager(); DataSourceContainer dataSourceContainer = repoxManagerDefault .getDataManager() .getDataSourceContainer(dataSourceUI.getDataSourceSet()); DataSource dataSource = dataSourceContainer.getDataSource(); dataSource.setExportDir(dataSourceUI.getExportDirectory()); String recordsPerFile; if (dataSourceUI.getRecordsPerFile().equals("All")) recordsPerFile = "-1"; else recordsPerFile = dataSourceUI.getRecordsPerFile(); ConfigSingleton.getRepoxContextUtil() .getRepoxManager() .getDataManager() .startExportDataSource( dataSourceUI.getDataSourceSet(), recordsPerFile, dataSourceUI.getExportFormat()); } catch (Exception e) { throw new ServerSideException(Util.stackTraceToString(e)); } return true; }
public void addNotListedOldTasks(String dataSetId) { try { DataSource dataSource = ConfigSingleton.getRepoxContextUtil() .getRepoxManager() .getDataManager() .getDataSourceContainer(dataSetId) .getDataSource(); for (String logFileName : dataSource.getLogFilenames()) { boolean matchFound = false; for (OldTask oldTask : dataSource.getOldTasksList()) { if (oldTask.getLogName().equals(logFileName)) { matchFound = true; break; } } if (!matchFound && dataSource.getStatus() != DataSource.StatusDS.RUNNING) { String oldTaskId = dataSetId + "_" + UUID.randomUUID().toString(); StatusAndRecords statusAndRecords = getStatusAndRecordsFromLogFile(dataSetId, logFileName); OldTask oldTask = new OldTask( dataSource, oldTaskId, logFileName, "incrementalIngest", statusAndRecords.getStatus(), "0", "3", "300", convertDateToString(getLogFileDate(dataSetId, logFileName)), statusAndRecords.getRecords()); dataSource.getOldTasksList().add(oldTask); ConfigSingleton.getRepoxContextUtil() .getRepoxManager() .getDataManager() .saveOldTask(oldTask); log.warn("New Old Tasks added from Log Files for the data set: " + dataSetId); } } } catch (DocumentException e) { e.printStackTrace(); // To change body of catch statement use File | Settings | File // Templates. } catch (IOException e) { e.printStackTrace(); // To change body of catch statement use File | Settings | File // Templates. } catch (StringIndexOutOfBoundsException e) { // Do nothing } catch (ArrayIndexOutOfBoundsException e) { // Do nothing } catch (Exception e) { // Do nothing } }
private static void loadCountries() { try { String countriesFilename = RepoxContextUtilDefault.COUNTRIES_FILENAME; File countriesFile = new File( ConfigSingleton.getRepoxContextUtil() .getRepoxManager() .getConfiguration() .getXmlConfigPath(), countriesFilename); countryMap = new LinkedHashMap<String, String>(); BufferedReader reader = new BufferedReader( new InputStreamReader( new FileInputStream(countriesFile), Charset.forName("ISO-8859-1"))); String currentLine = ""; while ((currentLine = reader.readLine()) != null) { String[] country = currentLine.split("\t"); if (country.length != 2) { log.error("Error parsing countries file - not a pair CODE\tCOUNTRY: " + currentLine); } else { countryMap.put(country[0].toLowerCase().trim(), country[1].trim()); } } reader.close(); } catch (IOException e) { log.error( "Error loading countries from file: " + RepoxContextUtilDefault.COUNTRIES_FILENAME, e); } }
private StatusAndRecords getStatusAndRecordsFromLogFile(String dataSetId, String logFileName) { File logFile = new File( ConfigSingleton.getRepoxContextUtil() .getRepoxManager() .getConfiguration() .getRepositoryPath() + File.separator + dataSetId + File.separator + "logs" + File.separator + logFileName); try { SAXReader reader = new SAXReader(); Document logDocument = reader.read(logFile); String status = logDocument.valueOf("//report/status"); String records = logDocument.valueOf("//report/records"); return new StatusAndRecords(status, records); } catch (DocumentException e) { return new StatusAndRecords("OK", "0"); } }
protected static void createXslFile(String fileName, MappingScript script) throws IOException { File xsltDir = ConfigSingleton.getRepoxContextUtil() .getRepoxManager() .getMetadataTransformationManager() .getXsltDir(); if (!xsltDir.exists()) xsltDir.mkdirs(); File xslFile = new File(xsltDir, fileName.toLowerCase() + XSL_END); StreamResult tmpResult = new StreamResult(new FileOutputStream(xslFile)); XsltStylesheet xslt = new XSLTCompiler(new ToolsetManagerImpl<XsltFunction>(XsltToolsetLibrary.getToolsets())) .compile(script); new XsltWriter().write(xslt, tmpResult); tmpResult.getOutputStream().close(); /* DUMMY FILE CREATION CODE File xsltDir = ConfigSingleton.getRepoxContextUtil().getRepoxManager().getMetadataTransformationManager().getXsltDir(); if(!xsltDir.exists()) xsltDir.mkdirs(); tmpFile = new File(xsltDir, fileName.toLowerCase()+XSL_END); FileWriter fstream = new FileWriter(tmpFile); BufferedWriter outFile = new BufferedWriter(fstream); outFile.write("<This is a dummy xslt>"); outFile.close();*/ // System.out.println("SERVER - XSL created"); }
@Before public void setUp() { try { ConfigSingleton.setRepoxContextUtil(new RepoxContextUtilEuropeana()); ConfigSingleton.getRepoxContextUtil().getRepoxManagerTest(); // id min hour day month weekday taskClass Parameters... // Jan 1st 00:00 Calendar firstRun = new GregorianCalendar(2009, 0, 1, 0, 0); goodTask = new ScheduledTask( "1", firstRun, Frequency.ONCE, null, new DataSourceIngestTask("1", "1", "false")); } catch (Exception e) { e.printStackTrace(); } }
protected static void createXmapFile(String fileName, MappingScript script) throws IOException { File xmapDir = ConfigSingleton.getRepoxContextUtil() .getRepoxManager() .getMetadataTransformationManager() .getXmapDir(); if (!xmapDir.exists()) xmapDir.mkdirs(); File xmapFile = new File(xmapDir, fileName.toLowerCase() + XMAP_END); StreamResult tmpResult = new StreamResult(new FileOutputStream(xmapFile)); new XMLMappingWriter().write(script, tmpResult); tmpResult.getOutputStream().close(); // System.out.println("SERVER - XMAP created"); }
protected static ResponseState validateTransformation( String id, String xslFilePath, String oldTransId) throws ServerSideException { try { ConfigSingleton.getRepoxContextUtil() .getRepoxManager() .getMetadataTransformationManager() .checkTransformationValidity(id, xslFilePath + XSL_END, oldTransId); return ResponseState.SUCCESS; } catch (SameStylesheetTransformationException e) { return ResponseState.MAPPING_SAME_XSL; } catch (AlreadyExistsException e) { return ResponseState.ALREADY_EXISTS; } catch (Exception e) { e.printStackTrace(); throw new ServerSideException(Util.stackTraceToString(e)); } }
public static MappingScriptProxy getExistingMappingModel(TransformationUI transformationUI) { try { File xmapDir = ConfigSingleton.getRepoxContextUtil() .getRepoxManager() .getMetadataTransformationManager() .getXmapDir(); String mapFilePath = xmapDir.getPath() + File.separator + FilenameUtils.removeExtension(transformationUI.getXslFilePath()) + ".xmap"; URL tmp = new URL(transformationUI.getSourceSchema()); XMLSchema source = getXSDSchema(tmp); tmp = new URL(transformationUI.getDestSchema()); XMLSchema target = getXSDSchema(tmp); MappingScript mapping = getMapping(source, target, mapFilePath); return new Mapping2UIAdapter().adapt(mapping); } catch (IOException e) { e.printStackTrace(); return null; } }
protected static ResponseState saveTransformationMDR( TransformationUI transformationUI, String oldTransId) throws ServerSideException { try { String xslFilePath = FilenameUtils.removeExtension(transformationUI.getXslFilePath().toLowerCase()) + XSL_END; // System.out.println("SERVER - XSL path: " + xslFilePath); MetadataTransformation mtdTransformation = new MetadataTransformation( transformationUI.getIdentifier(), transformationUI.getDescription(), transformationUI.getSrcFormat(), transformationUI.getDestFormat(), xslFilePath, transformationUI.isEditable(), transformationUI.getIsXslVersion2(), transformationUI.getDestSchema(), transformationUI.getDestMetadataNamespace()); mtdTransformation.setSourceSchema(transformationUI.getSourceSchema()); mtdTransformation.setMDRCompliant(transformationUI.isMDRCompliant()); ConfigSingleton.getRepoxContextUtil() .getRepoxManager() .getMetadataTransformationManager() .saveMetadataTransformation(mtdTransformation, oldTransId); // System.out.println("SERVER - Transformation saved on the MDR"); return ResponseState.SUCCESS; } catch (SameStylesheetTransformationException e) { return ResponseState.MAPPING_SAME_XSL; } catch (AlreadyExistsException e) { return ResponseState.ALREADY_EXISTS; } catch (Exception e) { e.printStackTrace(); throw new ServerSideException(Util.stackTraceToString(e)); } }
public LightManager() { super(); ConfigSingleton.setRepoxContextUtil(new RepoxContextUtilDefault()); }