Package eu.scape_project.planning.model

Examples of eu.scape_project.planning.model.Plan


  }
     
  @Test
  public void constructWorkflowSteps_standardPlanReturnsAllStandardSteps() throws PlanningException {
    Plan plan = mock(Plan.class);
   
    // number of steps
    List<AbstractView> result = wfStepFactory.constructWorkflowSteps(plan);
    assertEquals(14, result.size());
   
View Full Code Here


            viewWorkflowManager.endWorkflow();
        }
       
        conversation.begin();

        plan = new Plan();

        plan.getPlanProperties().setAuthor(user.getFullName());
        plan.getPlanProperties().setPrivateProject(true);
        plan.getPlanProperties().setOwner(user.getUsername());
       
View Full Code Here

        Assert.assertTrue(conversationContext.isActive());

        DefineBasis defineBasis = defineBasisSource.get();
        Assert.assertNotNull(defineBasis);

        Plan plan = new Plan();
        plan.getPlanProperties().setName("Test Plan");
        plan.getPlanProperties().setAuthor(user.getUsername());
        plan.getPlanProperties().setOwner(user.getUsername());

        defineBasis.init(plan);
        Assert.assertNotNull(defineBasis.getPlan());

        defineBasis.save();
        log.info("stored plan");
        List<ValidationError> errors = new ArrayList<ValidationError>();

        Assert.assertTrue(defineBasis.proceed(errors));
        Assert.assertEquals(PlanState.BASIS_DEFINED, plan.getPlanProperties().getState());

        DefineSampleObjects defineSamples = defineSampleObjectSource.get();
        defineSamples.init(plan);

        Assert.assertFalse(defineSamples.proceed(errors));
View Full Code Here

        // Mock objects
        AbstractWorkflowStep step = mock(AbstractWorkflowStep.class);
        Mockito.doCallRealMethod().when(step).save();

        step.requiredPlanState = PlanState.CREATED;
        Plan p = new Plan();
        p.getPlanProperties().setState(PlanState.PLAN_VALIDATED);
        step.plan = p;

        PrepareChangesForPersist prepareChangesForPersist = mock(PrepareChangesForPersist.class);
        step.prepareChangesForPersist = prepareChangesForPersist;

        EntityManager em = mock(EntityManager.class);
        when(em.merge(p)).thenReturn(p);
        step.em = em;

        // Execute test
        step.save();

        // Verify results
        Assert.assertTrue(p.getPlanProperties().getState() == PlanState.CREATED);
    }
View Full Code Here

     *            PlanProperties-id of the plan to clone.
     * @return True if cloning was successful, false otherwise.
     */
    public boolean clonePlan(Integer planPropertiesId, String newOwner) {
        boolean success = false;
        Plan selectedPlan;
        try {
            selectedPlan = (Plan) em
                .createQuery("select p from Plan p where p.planProperties.id = " + planPropertiesId).getSingleResult();

            String binarydataTempPath = OS.getTmpPath() + "cloneplan_" + System.currentTimeMillis() + "/";
            File binarydataTempDir = new File(binarydataTempPath);
            binarydataTempDir.mkdirs();
            try {
                String tempFile = binarydataTempPath + "plan.xml";
                projectExportAction
                    .exportComplete(planPropertiesId, new FileOutputStream(tempFile), binarydataTempPath);
                List<Plan> plans = projectImporter.importPlans(new FileInputStream(tempFile));
                Notification notification = null;
                if (newOwner != null) {
                    User user = em.createQuery("Select u from User u where u.username = :username", User.class)
                        .setParameter("username", newOwner).getSingleResult();

                    for (Plan p : plans) {
                        PlanProperties prop = p.getPlanProperties();
                        prop.setDescription(newOwner + "'s copy of: " + prop.getDescription()
                            + " (originally created by " + prop.getOwner() + ")");
                        prop.setOwner(newOwner);
                        // mark this plan as a playground copy
                        prop.setPlayground(true);
                        prop.touch();
                        PrepareChangesForPersist prep = new PrepareChangesForPersist(newOwner);
                        prep.prepare(prop);

                        String message = "A copy has been created: <em>"
                            + prop.getName()
                            + " - "
                            + prop.getDescription()
                            + "</em>"
                            + "<br/>It is marked as playground. If you want to use it for serious planning, please change this in Plan Settings.";
                        notification = new Notification(UUID.randomUUID().toString(), new Date(), "PLATO", message,
                            user);
                    }
                }
                // store project
                storePlans(plans);
                success = true;
                log.debug("Plan '" + selectedPlan.getPlanProperties().getName() + "' successfully cloned.");
                if (notification != null) {
                    // and store notification as well
                    em.persist(notification);
                }
            } catch (Exception e) {
                log.error("Could not clone project: '" + selectedPlan.getPlanProperties().getName() + "'.", e);
            } finally {
                OS.deleteDirectory(binarydataTempDir);
            }
            return success;

View Full Code Here

     *            PlanPropertiesId of the plan to delete.
     * @return True if deletion was successful, false otherwise.
     */
    public boolean deletePlan(int planPropertiesId) {
        try {
            Plan plan = (Plan) em.createQuery("select p from Plan p where p.planProperties.id = " + planPropertiesId)
                .getSingleResult();
            planManager.deletePlan(plan);
            return true;
        } catch (Exception e) {
            log.error(e.getMessage(), e);
View Full Code Here

     *            PlanProperties id of the Plan to operate on.
     * @return Number of cleanedUp/removed Values objects.
     */
    private int cleanupProject(int pid) {
        try {
            Plan p = (Plan) em.createQuery("select p from Plan p where p.planProperties.id = " + pid).getSingleResult();
            List<String> alternativeNames = new ArrayList<String>();

            for (Alternative a : p.getAlternativesDefinition().getAlternatives()) {
                alternativeNames.add(a.getName());
            }

            int number = p.getTree().removeLooseValues(alternativeNames,
                p.getSampleRecordsDefinition().getRecords().size());
            log.info("cleaned up values for plan " + p.getPlanProperties().getName() + " - removed " + number
                + " Value(s) instances.");

            if (number > 0) {
                em.persist(p.getTree());
            }
            em.clear();

            return number;
        } catch (Exception e) {
View Full Code Here

            return 0;
        }
    }

    public boolean fixAlternativeNames(int pid) {
        Plan p = (Plan) em.createQuery("select p from Plan p where p.planProperties.id = " + pid).getSingleResult();
        log.debug("fixing alternative names of plan {}, {}", pid, p.getPlanProperties().getName());

        boolean fixed = false;
        for (Alternative a : p.getAlternativesDefinition().getAlternatives()) {
            String oldName = a.getName();
            String name = oldName.trim();
            if (!name.equals(oldName)) {
                name = p.getAlternativesDefinition().createUniqueName(name);
                try {
                    log.debug("Renaming alternative {} to {}", oldName, name);
                    p.renameAlternative(a, name);
                    a.setDescription(a.getDescription() + "\r\n(PLATO: Alternative name normalization: '" + oldName
                        + "' to '" + name + "')");
                    fixed = true;
                } catch (PlanningException e) {
                    log.error("Failed to rename alternative for plan " + pid, e);
                    return false;
                }
            }
        }
        if (fixed) {
            em.persist(p.getAlternativesDefinition());
            em.persist(p.getTree());
        }
        return true;
    }
View Full Code Here

     *            Plans to store.
     * @throws PlatoException
     */
    private void storePlans(List<Plan> plans) throws PlatoException {
        while (!plans.isEmpty()) {
            Plan plan = plans.get(0);
            projectImporter.storeDigitalObjects(plan);
            em.persist(plan);
            em.flush();

            plans.remove(plan);
View Full Code Here

        List<Plan> plans = parser.importProjects(in);

        Assert.assertTrue(plans.size() == 1);

        Plan plan = plans.get(0);
        Assert.assertNotNull(plan.getPlanProperties());
        Assert.assertNotNull(plan.getSampleRecordsDefinition());
        Assert.assertNotNull(plan.getProjectBasis());
        Assert.assertNotNull(plan.getRequirementsDefinition());
        Assert.assertNotNull(plan.getTree());
        Assert.assertNotNull(plan.getAlternativesDefinition());
        Assert.assertNotNull(plan.getEvaluation());
        Assert.assertNotNull(plan.getTransformation());
        Assert.assertNotNull(plan.getImportanceWeighting());
        Assert.assertNotNull(plan.getRecommendation());
        Assert.assertNotNull(plan.getDecision());
        Assert.assertNotNull(plan.getExecutablePlanDefinition());
        Assert.assertNotNull(plan.getPreservationActionPlan());
        Assert.assertNotNull(plan.getPlanDefinition());

        Assert.assertNotNull(plan.getChangeLog());
        Assert.assertTrue(plan.getChangeLog().getCreatedBy().equals("test1"));
    }
View Full Code Here

TOP

Related Classes of eu.scape_project.planning.model.Plan

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.