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);