/** * Delete file from repository * * @param instanceId * @return */ public boolean remove(String instanceId) { writeLock.lock(); try { RepositoryFile configFile = componentsFolder.getFile(instanceId); if (configFile == null) { logger.info("Component with id: {} is not in store.", instanceId); return false; } configFile.delete(); logger.info("Component {} was removed.", instanceId); } finally { writeLock.unlock(); } return true; }
@RequestMapping(method = RequestMethod.POST, produces = "application/json") @ResponseBody @RolesAllowed({ SecurityRoles.JOB_EDITOR }) public Map<String, String> deleteJob(@PathVariable("tenant") final String tenant, @PathVariable("job") String jobName) { logger.info("Request payload: {} - {}", tenant, jobName); jobName = jobName.replaceAll("\\+", " "); final TenantContext tenantContext = _contextFactory.getContext(tenant); final JobContext job = tenantContext.getJob(jobName); RepositoryFile file = job.getJobFile(); file.delete(); final RepositoryFile scheduleFile = tenantContext.getJobFolder().getFile( jobName + SchedulingServiceImpl.EXTENSION_SCHEDULE_XML); if (scheduleFile != null) { scheduleFile.delete(); } _eventPublisher.publishEvent(new JobDeletionEvent(this, tenant, jobName)); final Map<String, String> response = new TreeMap<String, String>(); response.put("job", jobName); response.put("action", "delete"); logger.debug("Response payload: {}", response); return response; }
private void deleteChildren(RepositoryFolder folder) { List<RepositoryFile> files = folder.getFiles(); for (RepositoryFile file : files) { file.delete(); } List<RepositoryFolder> folders = folder.getFolders(); for (RepositoryFolder subFolder : folders) { deleteChildren(subFolder); subFolder.delete(); } }
/** * Store configuration to repository in JSON * * @param configuration */ public void store(final ComponentStoreHolder configuration) { logger.info("Store component with id: {}", configuration.getInstanceId()); writeLock.lock(); RepositoryFile configFile = componentsFolder.getFile(configuration.getInstanceId()); if (configFile != null) { // I must delete old file. configFile.delete(); } try { componentsFolder.createFile(configuration.getInstanceId(), new Action<OutputStream>() { @Override public void run(OutputStream fileOutput) throws Exception { String jsonConf = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString( configuration); InputStream jsonConfStream = IOUtils.toInputStream(jsonConf); FileHelper.copy(jsonConfStream, fileOutput); } }); } finally { writeLock.unlock(); } }
private void renameSchedule(final RepositoryFile oldScheduleFile, final String nameInput, final RepositoryFolder jobFolder) { final String newScheduleFilename = nameInput + SchedulingServiceImpl.EXTENSION_SCHEDULE_XML; final Action<OutputStream> writeScheduleAction = new Action<OutputStream>() { @Override public void run(final OutputStream out) throws Exception { oldScheduleFile.readFile(new Action<InputStream>() { @Override public void run(final InputStream in) throws Exception { FileHelper.copy(in, out); } }); } }; final RepositoryFile newScheduleFile = jobFolder.getFile(newScheduleFilename); if (newScheduleFile == null) { jobFolder.createFile(newScheduleFilename, writeScheduleAction); } else { newScheduleFile.writeFile(writeScheduleAction); } oldScheduleFile.delete(); } }
@Override public void onApplicationEvent(JobDeletionEvent event) { final TenantIdentifier tenantIdentifier = new TenantIdentifier(event.getTenant()); final JobIdentifier jobIdentifier = new JobIdentifier(event.getJobName()); final List<RepositoryFile> results = resultDao.getResultsForJob(tenantIdentifier, jobIdentifier); for (RepositoryFile repositoryFile : results) { repositoryFile.delete(); } } }
public static void main(final String[] args) { final DCModuleImpl module = new DCModuleImpl(DataCleanerHome.get()); final DataCleanerConfiguration configuration = Guice.createInjector(module).getInstance(DataCleanerConfiguration.class); final ComponentReferenceDocumentationBuilder docBuilder = new ComponentReferenceDocumentationBuilder(configuration.getEnvironment().getDescriptorProvider()); final RepositoryFolder folder = configuration.getHomeFolder().toRepositoryFolder().getOrCreateFolder("documentation"); // clean up the directory final List<RepositoryFile> htmlFiles = folder.getFiles(null, ".html"); for (final RepositoryFile file : htmlFiles) { file.delete(); } docBuilder.writeDocumentationToRepositoryFolder(folder); System.out.println("Documentation written to: " + folder.getQualifiedPath()); } }
newFile.writeFile(writeAction); existingFile.delete();