List of usage examples for org.springframework.transaction.support TransactionCallbackWithoutResult TransactionCallbackWithoutResult
TransactionCallbackWithoutResult
From source file:org.orcid.core.cli.ResaveProfiles.java
private void processOrcid(final String orcid) { LOG.info("Resaving profile: {}", orcid); try {/*w w w . jav a 2 s . c o m*/ transactionTemplate.execute(new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(TransactionStatus status) { OrcidProfile orcidProfile = orcidProfileManager.retrieveOrcidProfile(orcid); Date originalLastModified = orcidProfile.getOrcidHistory().getLastModifiedDate().getValue() .toGregorianCalendar().getTime(); IndexingStatus originalIndexingStatus = profileDao.find(orcid).getIndexingStatus(); // Save it straight back - it will be saved back in the // new DB table automatically orcidProfileManager.updateOrcidProfile(orcidProfile); if (!updateLastModified) { profileDao.updateLastModifiedDateAndIndexingStatusWithoutResult(orcid, originalLastModified, originalIndexingStatus); } } }); } catch (RuntimeException e) { errorCount++; if (continueOnError) { LOG.error("Error saving profile: orcid={}", orcid, e); return; } else { throw e; } } doneCount++; }
From source file:org.orcid.core.manager.impl.EmailMessageSenderImpl.java
@Override public void sendEmailMessages() { LOGGER.info("About to send email messages"); List<String> orcidsWithMessagesToSend = notificationDao.findOrcidsWithNotificationsToSend(); for (final String orcid : orcidsWithMessagesToSend) { try {/* w w w . jav a 2s . c o m*/ transactionTemplate.execute(new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(TransactionStatus status) { LOGGER.info("Sending messages for orcid: {}", orcid); List<Notification> notifications = notificationManager.findUnsentByOrcid(orcid); LOGGER.info("Found {} messages to send for orcid: {}", notifications.size(), orcid); EmailMessage digestMessage = createDigest(orcid, notifications); digestMessage.setFrom(DIGEST_FROM_ADDRESS); EmailEntity primaryEmail = profileDao.find(orcid).getPrimaryEmail(); if (primaryEmail == null) { LOGGER.info("No primary email for orcid: " + orcid); return; } digestMessage.setTo(primaryEmail.getId()); boolean successfullySent = mailGunManager.sendEmail(digestMessage.getFrom(), digestMessage.getTo(), digestMessage.getSubject(), digestMessage.getBodyText(), digestMessage.getBodyHtml()); if (successfullySent) { flagAsSent(notifications); } } }); } catch (RuntimeException e) { LOGGER.warn("Problem sending email message to user: " + orcid, e); } } LOGGER.info("Finished sending email messages"); }
From source file:org.orcid.core.manager.impl.OrcidProfileManagerImpl.java
public void processProfilePendingIndexingInTransaction(final String orcid) { transactionTemplate.execute(new TransactionCallbackWithoutResult() { protected void doInTransactionWithoutResult(TransactionStatus status) { LOG.info("About to index profile: {}", orcid); OrcidProfile orcidProfile = retrievePublicOrcidProfile(orcid); if (orcidProfile == null) { LOG.debug("Null profile found during indexing: {}", orcid); } else { LOG.debug("Got profile to index: {}", orcid); orcidIndexManager.persistProfileInformationForIndexingIfNecessary(orcidProfile); profileDao.updateIndexingStatus(orcid, IndexingStatus.DONE); }/* ww w . j a v a 2 s . c om*/ } }); }
From source file:org.orcid.core.manager.impl.OrcidProfileManagerImpl.java
private void processUnverifiedEmails7DaysInTransaction(final String email) { transactionTemplate.execute(new TransactionCallbackWithoutResult() { @Override//from w w w. jav a 2 s . c o m @Transactional protected void doInTransactionWithoutResult(TransactionStatus status) { OrcidProfile orcidProfile = retrieveOrcidProfileByEmail(email); notificationManager.sendVerificationReminderEmail(orcidProfile, email); emailEventDao.persist(new EmailEventEntity(email, EmailEventType.VERIFY_EMAIL_7_DAYS_SENT)); emailEventDao.flush(); } }); }
From source file:org.orcid.core.manager.impl.OrcidProfileManagerImpl.java
private void processUnclaimedProfileForReminderInTransaction(final String orcid) { transactionTemplate.execute(new TransactionCallbackWithoutResult() { @Override// w ww . java 2 s . c o m protected void doInTransactionWithoutResult(TransactionStatus status) { processUnclaimedProfileForReminder(orcid); } }); }
From source file:org.orcid.core.manager.impl.OrgDisambiguatedManagerImpl.java
private void processDisambiguatedOrgInTransaction(final OrgDisambiguatedEntity entity) { transactionTemplate.execute(new TransactionCallbackWithoutResult() { @Override// www . j a v a2 s .c o m protected void doInTransactionWithoutResult(TransactionStatus arg0) { processDisambiguatedOrg(orgDisambiguatedDao.find(entity.getId())); } }); }
From source file:org.pentaho.aggdes.ui.exec.impl.JdbcTemplateSqlExecutor.java
public void execute(final String[] sql, final ExecutorCallback callback) throws DataAccessException { Exception exceptionDuringExecute = null; DatabaseMeta dbMeta = connectionModel.getDatabaseMeta(); String url = null;/*from ww w . ja va2s.c o m*/ try { url = dbMeta.getURL(); } catch (KettleDatabaseException e) { throw new DataAccessException("DatabaseMeta problem", e) { private static final long serialVersionUID = -3457360074729938909L; }; } // create the datasource DataSource ds = new SingleConnectionDataSource(dbMeta.getDriverClass(), url, dbMeta.getUsername(), dbMeta.getPassword(), false); // create the jdbc template final JdbcTemplate jt = new JdbcTemplate(ds); // create the transaction manager DataSourceTransactionManager tsMan = new DataSourceTransactionManager(ds); // create the transaction template TransactionTemplate txTemplate = new TransactionTemplate(tsMan); // set behavior txTemplate.setPropagationBehavior(DefaultTransactionDefinition.PROPAGATION_REQUIRES_NEW); final String noCommentSql[] = removeCommentsAndSemicolons(connectionModel.getSchema(), sql); try { // run the code in a transaction txTemplate.execute(new TransactionCallbackWithoutResult() { public void doInTransactionWithoutResult(TransactionStatus status) { jt.batchUpdate(noCommentSql); } }); } catch (DataAccessException e) { if (logger.isErrorEnabled()) { logger.error("data access exception", e); } exceptionDuringExecute = e; } callback.executionComplete(exceptionDuringExecute); }
From source file:org.pentaho.di.repository.pur.PurRepositoryTest.java
protected void createUserHomeFolder(final ITenant theTenant, final String theUsername) { IPentahoSession origPentahoSession = PentahoSessionHolder.getSession(); Authentication origAuthentication = SecurityContextHolder.getContext().getAuthentication(); StandaloneSession pentahoSession = new StandaloneSession(repositoryAdminUsername); pentahoSession.setAuthenticated(null, repositoryAdminUsername); PentahoSessionHolder.setSession(pentahoSession); try {/*from w w w. j a v a 2s. c o m*/ txnTemplate.execute(new TransactionCallbackWithoutResult() { public void doInTransactionWithoutResult(final TransactionStatus status) { Builder aclsForUserHomeFolder = null; Builder aclsForTenantHomeFolder = null; ITenant tenant = null; String username = null; if (theTenant == null) { tenant = getTenant(username, true); username = getPrincipalName(theUsername, true); } else { tenant = theTenant; username = theUsername; } if (tenant == null || tenant.getId() == null) { tenant = getCurrentTenant(); } if (tenant == null || tenant.getId() == null) { tenant = JcrTenantUtils.getDefaultTenant(); } RepositoryFile userHomeFolder = null; String userId = userNameUtils.getPrincipleId(theTenant, username); final RepositoryFileSid userSid = new RepositoryFileSid(userId); RepositoryFile tenantHomeFolder = null; RepositoryFile tenantRootFolder = null; // Get the Tenant Root folder. If the Tenant Root folder does not exist then exit. tenantRootFolder = repositoryFileDao .getFileByAbsolutePath(ServerRepositoryPaths.getTenantRootFolderPath(theTenant)); if (tenantRootFolder != null) { // Try to see if Tenant Home folder exist tenantHomeFolder = repositoryFileDao .getFileByAbsolutePath(ServerRepositoryPaths.getTenantHomeFolderPath(theTenant)); if (tenantHomeFolder == null) { String ownerId = userNameUtils.getPrincipleId(theTenant, username); RepositoryFileSid ownerSid = new RepositoryFileSid(ownerId, Type.USER); String tenantAuthenticatedRoleId = roleNameUtils.getPrincipleId(theTenant, tenantAuthenticatedRoleName); RepositoryFileSid tenantAuthenticatedRoleSid = new RepositoryFileSid( tenantAuthenticatedRoleId, Type.ROLE); aclsForTenantHomeFolder = new RepositoryFileAcl.Builder(userSid) .ace(tenantAuthenticatedRoleSid, EnumSet.of(RepositoryFilePermission.READ)); aclsForUserHomeFolder = new RepositoryFileAcl.Builder(userSid).ace(ownerSid, EnumSet.of(RepositoryFilePermission.ALL)); tenantHomeFolder = repositoryFileDao.createFolder(tenantRootFolder.getId(), new RepositoryFile.Builder(ServerRepositoryPaths.getTenantHomeFolderName()) .folder(true).build(), aclsForTenantHomeFolder.build(), "tenant home folder"); } else { String ownerId = userNameUtils.getPrincipleId(theTenant, username); RepositoryFileSid ownerSid = new RepositoryFileSid(ownerId, Type.USER); aclsForUserHomeFolder = new RepositoryFileAcl.Builder(userSid).ace(ownerSid, EnumSet.of(RepositoryFilePermission.ALL)); } // now check if user's home folder exist userHomeFolder = repositoryFileDao.getFileByAbsolutePath( ServerRepositoryPaths.getUserHomeFolderPath(theTenant, username)); if (userHomeFolder == null) { userHomeFolder = repositoryFileDao.createFolder(tenantHomeFolder.getId(), new RepositoryFile.Builder(username).folder(true).build(), aclsForUserHomeFolder.build(), "user home folder"); //$NON-NLS-1$ } } } }); } finally { // Switch our identity back to the original user. PentahoSessionHolder.setSession(origPentahoSession); SecurityContextHolder.getContext().setAuthentication(origAuthentication); } }
From source file:org.pentaho.di.ui.repository.pur.repositoryexplorer.model.UIEERepositoryDirectoryIT.java
private void createUserHomeFolder(final ITenant theTenant, final String theUsername) { IPentahoSession origPentahoSession = PentahoSessionHolder.getSession(); Authentication origAuthentication = SecurityContextHolder.getContext().getAuthentication(); StandaloneSession pentahoSession = new StandaloneSession(repositoryAdminUsername); pentahoSession.setAuthenticated(null, repositoryAdminUsername); PentahoSessionHolder.setSession(pentahoSession); try {/*from ww w. ja va 2s . c o m*/ txnTemplate.execute(new TransactionCallbackWithoutResult() { public void doInTransactionWithoutResult(final TransactionStatus status) { Builder aclsForUserHomeFolder = null; Builder aclsForTenantHomeFolder = null; ITenant tenant = null; String username = null; if (theTenant == null) { tenant = getTenant(username, true); username = getPrincipalName(theUsername, true); } else { tenant = theTenant; username = theUsername; } if (tenant == null || tenant.getId() == null) { tenant = getCurrentTenant(); } if (tenant == null || tenant.getId() == null) { tenant = JcrTenantUtils.getDefaultTenant(); } RepositoryFile userHomeFolder = null; String userId = userNameUtils.getPrincipleId(theTenant, username); final RepositoryFileSid userSid = new RepositoryFileSid(userId); RepositoryFile tenantHomeFolder = null; RepositoryFile tenantRootFolder = null; // Get the Tenant Root folder. If the Tenant Root folder does not exist then exit. tenantRootFolder = repositoryFileDao .getFileByAbsolutePath(ServerRepositoryPaths.getTenantRootFolderPath(theTenant)); if (tenantRootFolder != null) { // Try to see if Tenant Home folder exist tenantHomeFolder = repositoryFileDao .getFileByAbsolutePath(ServerRepositoryPaths.getTenantHomeFolderPath(theTenant)); if (tenantHomeFolder == null) { String ownerId = userNameUtils.getPrincipleId(theTenant, username); RepositoryFileSid ownerSid = new RepositoryFileSid(ownerId, Type.USER); String tenantAuthenticatedRoleId = roleNameUtils.getPrincipleId(theTenant, tenantAuthenticatedRoleName); RepositoryFileSid tenantAuthenticatedRoleSid = new RepositoryFileSid( tenantAuthenticatedRoleId, Type.ROLE); aclsForTenantHomeFolder = new RepositoryFileAcl.Builder(userSid) .ace(tenantAuthenticatedRoleSid, EnumSet.of(RepositoryFilePermission.READ)); aclsForUserHomeFolder = new RepositoryFileAcl.Builder(userSid).ace(ownerSid, EnumSet.of(RepositoryFilePermission.ALL)); tenantHomeFolder = repositoryFileDao.createFolder(tenantRootFolder.getId(), new RepositoryFile.Builder(ServerRepositoryPaths.getTenantHomeFolderName()) .folder(true).build(), aclsForTenantHomeFolder.build(), "tenant home folder"); } else { String ownerId = userNameUtils.getPrincipleId(theTenant, username); RepositoryFileSid ownerSid = new RepositoryFileSid(ownerId, Type.USER); aclsForUserHomeFolder = new RepositoryFileAcl.Builder(userSid).ace(ownerSid, EnumSet.of(RepositoryFilePermission.ALL)); } // now check if user's home folder exist userHomeFolder = repositoryFileDao.getFileByAbsolutePath( ServerRepositoryPaths.getUserHomeFolderPath(theTenant, username)); if (userHomeFolder == null) { userHomeFolder = repositoryFileDao.createFolder(tenantHomeFolder.getId(), new RepositoryFile.Builder(username).folder(true).build(), aclsForUserHomeFolder.build(), "user home folder"); //$NON-NLS-1$ } } } }); } finally { // Switch our identity back to the original user. PentahoSessionHolder.setSession(origPentahoSession); SecurityContextHolder.getContext().setAuthentication(origAuthentication); } }
From source file:org.pentaho.platform.repository2.unified.DefaultUnifiedRepositoryBase.java
protected void createUserHomeFolder(final ITenant theTenant, final String theUsername) { IPentahoSession origPentahoSession = PentahoSessionHolder.getSession(); Authentication origAuthentication = SecurityContextHolder.getContext().getAuthentication(); StandaloneSession pentahoSession = new StandaloneSession(repositoryAdminUsername); pentahoSession.setAuthenticated(null, repositoryAdminUsername); PentahoSessionHolder.setSession(pentahoSession); try {/* w w w.j a v a 2 s .co m*/ txnTemplate.execute(new TransactionCallbackWithoutResult() { public void doInTransactionWithoutResult(final TransactionStatus status) { RepositoryFileAcl.Builder aclsForUserHomeFolder = null; RepositoryFileAcl.Builder aclsForTenantHomeFolder = null; ITenant tenant = null; String username = null; if (theTenant == null) { tenant = getTenant(username, true); username = getPrincipalName(theUsername, true); } else { tenant = theTenant; username = theUsername; } if (tenant == null || tenant.getId() == null) { tenant = getCurrentTenant(); } if (tenant == null || tenant.getId() == null) { tenant = JcrTenantUtils.getDefaultTenant(); } RepositoryFile userHomeFolder = null; String userId = userNameUtils.getPrincipleId(theTenant, username); final RepositoryFileSid userSid = new RepositoryFileSid(userId); RepositoryFile tenantHomeFolder = null; RepositoryFile tenantRootFolder = null; // Get the Tenant Root folder. If the Tenant Root folder does not exist then exit. tenantRootFolder = repositoryFileDao .getFileByAbsolutePath(ServerRepositoryPaths.getTenantRootFolderPath(theTenant)); if (tenantRootFolder != null) { // Try to see if Tenant Home folder exist tenantHomeFolder = repositoryFileDao .getFileByAbsolutePath(ServerRepositoryPaths.getTenantHomeFolderPath(theTenant)); if (tenantHomeFolder == null) { String ownerId = userNameUtils.getPrincipleId(theTenant, username); RepositoryFileSid ownerSid = new RepositoryFileSid(ownerId, RepositoryFileSid.Type.USER); String tenantAuthenticatedRoleId = roleNameUtils.getPrincipleId(theTenant, tenantAuthenticatedRoleName); RepositoryFileSid tenantAuthenticatedRoleSid = new RepositoryFileSid( tenantAuthenticatedRoleId, RepositoryFileSid.Type.ROLE); aclsForTenantHomeFolder = new RepositoryFileAcl.Builder(userSid) .ace(tenantAuthenticatedRoleSid, EnumSet.of(RepositoryFilePermission.READ)); aclsForUserHomeFolder = new RepositoryFileAcl.Builder(userSid).ace(ownerSid, EnumSet.of(RepositoryFilePermission.ALL)); tenantHomeFolder = repositoryFileDao.createFolder(tenantRootFolder.getId(), new RepositoryFile.Builder(ServerRepositoryPaths.getTenantHomeFolderName()) .folder(true).build(), aclsForTenantHomeFolder.build(), "tenant home folder"); } else { String ownerId = userNameUtils.getPrincipleId(theTenant, username); RepositoryFileSid ownerSid = new RepositoryFileSid(ownerId, RepositoryFileSid.Type.USER); aclsForUserHomeFolder = new RepositoryFileAcl.Builder(userSid).ace(ownerSid, EnumSet.of(RepositoryFilePermission.ALL)); } // now check if user's home folder exist userHomeFolder = repositoryFileDao.getFileByAbsolutePath( ServerRepositoryPaths.getUserHomeFolderPath(theTenant, username)); if (userHomeFolder == null) { userHomeFolder = repositoryFileDao.createFolder(tenantHomeFolder.getId(), new RepositoryFile.Builder(username).folder(true).build(), aclsForUserHomeFolder.build(), "user home folder"); //$NON-NLS-1$ } } } }); } finally { // Switch our identity back to the original user. PentahoSessionHolder.setSession(origPentahoSession); SecurityContextHolder.getContext().setAuthentication(origAuthentication); } }