WorkflowManager { public Job addJob(JobDefinition jobProfile, String xml, CatalogConfiguration catalog, BigDecimal rdczId, UserProfile defaultUser, AppConfiguration appConfiguration ) throws WorkflowException { Map<String, UserProfile> users = createUserMap(); PhysicalMaterial physicalMaterial = new PhysicalMaterialBuilder() .setCatalog(catalog).setMetadata(xml).setRdczId(rdczId) .build(); Transaction tx = daoFactory.createTransaction(); WorkflowJobDao jobDao = daoFactory.createWorkflowJobDao(); WorkflowTaskDao taskDao = daoFactory.createWorkflowTaskDao(); WorkflowParameterDao paramDao = daoFactory.createWorkflowParameterDao(); WorkflowMaterialDao materialDao = daoFactory.createWorkflowMaterialDao(); jobDao.setTransaction(tx); taskDao.setTransaction(tx); paramDao.setTransaction(tx); materialDao.setTransaction(tx); Timestamp now = new Timestamp(System.currentTimeMillis()); String jobLabel = StringUtils.defaultIfEmpty(physicalMaterial.getLabel(), "?"); try { Job job = createJob(jobDao, now, jobLabel, jobProfile, null, users, defaultUser); Map<String, Material> materialCache = new HashMap<>(); for (StepDefinition step : jobProfile.getSteps()) { if (!step.isOptional()) { Task task = createTask(taskDao, now, job, jobProfile, step, users, defaultUser); createTaskParams(paramDao, step, task); createMaterials(materialDao, step, task, materialCache, physicalMaterial, appConfiguration); } } tx.commit(); return job; } catch (Throwable ex) { tx.rollback(); WorkflowException nex = new WorkflowException("Cannot add job: " + jobProfile.getName(), ex); throw (ex instanceof WorkflowException) ? nex.copy((WorkflowException) ex) : nex.addUnexpectedError(); } finally { tx.close(); } } WorkflowManager(WorkflowProfiles wp, DaoFactory daoFactory, UserManager users); static WorkflowManager getInstance(); static void setInstance(WorkflowManager instance); Job getJob(BigDecimal id); List<JobView> findJob(JobFilter filter); List<MaterialView> findMaterial(MaterialFilter filter); MaterialView createDigitalMaterialFromPhysical(DigitalObjectManager.CreateHandler handler, MaterialView view); Material updateMaterial(MaterialView view); Job getJobs(BigDecimal id); List<TaskParameterView> findParameter(TaskParameterFilter filter); Job updateJob(Job job); TaskManager tasks(); Job addJob(JobDefinition jobProfile, String xml,
            CatalogConfiguration catalog, BigDecimal rdczId, UserProfile defaultUser, AppConfiguration appConfiguration
    ); Job addSubjob(JobDefinition jobProfile, BigDecimal parentId,
            UserProfile defaultUser, WorkflowDefinition profiles, AppConfiguration appConfiguration
    );  }
@Test public void testAddJob() throws Exception { IDataSet db = database( support.loadFlatXmlDataStream(EmpireWorkflowJobDaoTest.class, "user.xml"), emptyBatchSet(schema) ); final IDatabaseConnection dbcon = support.getConnection(); support.cleanInsert(dbcon, db); dbcon.getConnection().commit(); dbcon.close(); WorkflowManager wm = initWorkflowManager("WorkflowManagerAddProfile.xml"); WorkflowDefinition workflow = wp.getProfiles(); assertNotNull(workflow); JobDefinition jobProfile = workflow.getJobs().get(0); assertNotNull(jobProfile); CatalogConfiguration c = new CatalogConfiguration("testCatalogId", "", new BaseConfiguration() {{ addProperty(CatalogConfiguration.PROPERTY_URL, "tcp: addProperty(CatalogConfiguration.PROPERTY_NAME, "test"); addProperty(CatalogConfiguration.PROPERTY_TYPE, Z3950Catalog.TYPE); }}); String mods = IOUtils.toString(WorkflowManagerTest.class.getResource("rdczmods.xml")); Job job = wm.addJob(jobProfile, mods, c, null, null, null); assertNotNull(job); Job getJob = wm.getJob(job.getId()); assertNotNull(getJob); JobFilter filter = new JobFilter(); filter.setId(job.getId()); Locale locale = new Locale("cs"); filter.setLocale(locale); List<JobView> findJob = wm.findJob(filter); assertEquals(1, findJob.size()); assertEquals("csTitle", findJob.get(0).getProfileLabel()); TaskFilter taskFilter = new TaskFilter(); taskFilter.setLocale(locale); taskFilter.setJobId(job.getId()); List<TaskView> findTask = wm.tasks().findTask(taskFilter, workflow); assertEquals(2, findTask.size()); assertEquals(job.getId(), findTask.get(0).getJobId()); MaterialFilter materialFilter = new MaterialFilter(); materialFilter.setJobId(job.getId()); materialFilter.setLocale(locale); List<MaterialView> findMaterial = wm.findMaterial(materialFilter); assertEquals(2, findMaterial.size()); TaskParameterFilter paramFilter = new TaskParameterFilter(); paramFilter.setLocale(locale); paramFilter.setProfileName("param.id1"); List<TaskParameterView> findParameter = wm.findParameter(paramFilter); assertEquals(2, findParameter.size()); assertEquals("param.id1", findParameter.get(0).getParamRef()); assertEquals("param.id1.value", findParameter.get(0).getValue()); assertEquals(job.getId(), findParameter.get(0).getJobId()); assertEquals("Param1", findParameter.get(0).getProfileLabel()); assertEquals("param.id2", findParameter.get(1).getParamRef()); assertNull(findParameter.get(1).getValue()); assertEquals(job.getId(), findParameter.get(1).getJobId()); assertEquals("param.id2", findParameter.get(1).getProfileLabel()); assertEquals(findParameter.get(0).getTaskId(), findParameter.get(1).getTaskId()); assertEquals("task.id1", findParameter.get(1).getTaskProfileName()); assertEquals("proarc.devices", findParameter.get(1).getValueMapId()); assertEquals(ValueMapSource.PROARC, findParameter.get(1).getValueMapType()); assertEquals(Boolean.TRUE, findParameter.get(1).getRequired()); assertEquals(ValueType.STRING, findParameter.get(1).getValueType()); }