protected void commit() { Presentations presentations = component.getPresentations(); Document doc = DocumentHelper.createDocument(); doc.setRootElement(doc.addElement("presentation")); component.saveSettings(doc.getRootElement()); String xml = Dom4j.writeDocument(doc, false); presentation.setXml(xml); presentation.setName(nameField.getValue()); presentation.setAutoSave(autoSaveField.getValue()); presentation.setDefault(defaultField.getValue()); User user = sessionSource.getUserSession().getCurrentOrSubstitutedUser(); boolean userOnly = !allowGlobalPresentations || !BooleanUtils.isTrue(globalField.getValue()); presentation.setUser(userOnly ? user : null); if (log.isTraceEnabled()) { log.trace(String.format("XML: %s", Dom4j.writeDocument(doc, true))); } if (isNew) { presentations.add(presentation); } else { presentations.modify(presentation); } presentations.commit(); addCloseListener(e -> { if (isNew) { component.applyPresentation(presentation.getId()); } }); }
protected Map<UUID, Presentation> copyPresentations(User fromUser, User toUser) { Map<UUID, Presentation> presentationMap = new HashMap<>(); try (Transaction tx = persistence.createTransaction()) { EntityManager em = persistence.getEntityManager(); // delete existing Query delete = em.createQuery("delete from sec$Presentation p where p.user.id = ?1"); delete.setParameter(1, toUser.getId()); delete.executeUpdate(); // copy settings TypedQuery<Presentation> selectQuery = em.createQuery( "select p from sec$Presentation p where p.user.id = ?1", Presentation.class); selectQuery.setParameter(1, fromUser.getId()); List<Presentation> presentations = selectQuery.getResultList(); for (Presentation presentation : presentations) { Presentation newPresentation = metadata.create(Presentation.class); newPresentation.setUser(toUser); newPresentation.setComponentId(presentation.getComponentId()); newPresentation.setAutoSave(presentation.getAutoSave()); newPresentation.setName(presentation.getName()); newPresentation.setXml(presentation.getXml()); presentationMap.put(presentation.getId(), newPresentation); em.persist(newPresentation); } tx.commit(); return presentationMap; } }