com.atlassian.sal.api.transaction.TransactionCallback Java Examples
The following examples show how to use
com.atlassian.sal.api.transaction.TransactionCallback.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: KitchenDutyPlanningResource.java From kitchen-duty-plugin-for-atlassian-jira with MIT License | 6 votes |
/** * Get the Weeks assigned to the User. * * @param weekNumber * @return */ @GET @Path("/user/{username}/weeks") @Produces({MediaType.APPLICATION_JSON}) @AnonymousAllowed public Response getWeeksForUser(@PathParam("username") final String username) { User[] users = activeObjects.executeInTransaction(new TransactionCallback<User[]>() { @Override public User[] doInTransaction() { return activeObjects.find(User.class, Query.select().where("NAME = ?", username)); } }); List<KitchenDutyPlanningResourceWeekModel> weeks = new ArrayList<>(); if (users != null && users.length > 0) { for (Week week : users[0].getWeeks()) { weeks.add(new KitchenDutyPlanningResourceWeekModel(week.getID(), week.getWeek())); } } return Response.ok(weeks).build(); }
Example #2
Source File: KitchenDutyPlanningResource.java From kitchen-duty-plugin-for-atlassian-jira with MIT License | 6 votes |
/** * Get all Users assigned to the weekNumber. * * @param weekNumber * @return */ @GET @Path("/week/{weekNumber}/users") @Produces({MediaType.APPLICATION_JSON}) @AnonymousAllowed public Response getUsersForWeek(@PathParam("weekNumber") final Integer weekNumber) { Week[] weeks = activeObjects.executeInTransaction(new TransactionCallback<Week[]>() { @Override public Week[] doInTransaction() { return activeObjects.find(Week.class, Query.select().where("WEEK = ?", weekNumber)); } }); List<KitchenDutyPlanningResourceUserModel> users = new ArrayList<>(); if (weeks != null && weeks.length > 0) { for (User user : weeks[0].getUsers()) { users.add(new KitchenDutyPlanningResourceUserModel(user.getID(), user.getName())); } } return Response.ok(users).build(); }
Example #3
Source File: KitchenDutyPlanningResource.java From kitchen-duty-plugin-for-atlassian-jira with MIT License | 6 votes |
@GET @Path("/user/{username}/weeks") @Produces({MediaType.APPLICATION_JSON}) @AnonymousAllowed public Response getWeeksForUser(@PathParam("username") final String username) { User[] users = activeObjects.executeInTransaction(new TransactionCallback<User[]>() { @Override public User[] doInTransaction() { return activeObjects.find(User.class, Query.select().where("NAME = ?", username)); } }); List<KitchenDutyPlanningResourceWeekModel> weeks = new ArrayList<>(); if (users != null && users.length > 0) { for (Week week : users[0].getWeeks()) { weeks.add(new KitchenDutyPlanningResourceWeekModel(week.getID(), week.getWeek())); } } return Response.ok(weeks).build(); }
Example #4
Source File: KitchenDutyActiveObjectHelper.java From kitchen-duty-plugin-for-atlassian-jira with MIT License | 6 votes |
public static List<User> getUsersAssignedToWeekInTransaction(ActiveObjects activeObjects, Week week) { List<User> users = new ArrayList<>(); if (week != null) { UserToWeek[] relationships = activeObjects.executeInTransaction(new TransactionCallback<UserToWeek[]>() { @Override public UserToWeek[] doInTransaction() { return KitchenDutyActiveObjectHelper.findAllRelationships(activeObjects, week); } }); if (relationships != null) { for (UserToWeek userToWeek : relationships) { users.add(userToWeek.getUser()); } } } return users; }
Example #5
Source File: KitchenDutyPlanningResource.java From kitchen-duty-plugin-for-atlassian-jira with MIT License | 5 votes |
@GET @Path("/user/{username}/weeks") @Produces({MediaType.APPLICATION_JSON}) @AnonymousAllowed public Response getWeeksForUser(@PathParam("username") final String username) { // AUTHENTICATION if (!this.isUserLoggedIn()) { return getUnauthorizedErrorResponse(); } // AUTHORIZATION if (this.isUserNotAdmin()) { return getForbiddenErrorResponse(); } // BUSINESS LOGIC User[] users = activeObjects.executeInTransaction(new TransactionCallback<User[]>() { @Override public User[] doInTransaction() { return activeObjects.find(User.class, Query.select().where("NAME = ?", username)); } }); List<KitchenDutyPlanningResourceWeekModel> weeks = new ArrayList<>(); if (users != null && users.length > 0) { for (Week week : users[0].getWeeks()) { weeks.add(new KitchenDutyPlanningResourceWeekModel(week.getID(), week.getWeek())); } } return Response.ok(weeks).build(); }
Example #6
Source File: KitchenDutyPlanningResource.java From kitchen-duty-plugin-for-atlassian-jira with MIT License | 5 votes |
@DELETE @Path("/week/{weekNumber}/users") @Produces({MediaType.APPLICATION_JSON}) @AnonymousAllowed public Response deleteUserFomWeek(@PathParam("weekNumber") final Integer weekNumber, final KitchenDutyPlanningResourceUserModel userParam) { activeObjects.executeInTransaction(new TransactionCallback<Void>() { @Override public Void doInTransaction() { // // WEEK // Week week = KitchenDutyActiveObjectHelper.findUniqueWeek(activeObjects, weekNumber); if (week == null) { // week does not exist => no relation to delete return null; } // // USER // User user = KitchenDutyActiveObjectHelper.findUniqueUser(activeObjects, userParam.getUsername()); if (user == null) { // user does not exist => no relation to delete return null; } // // Delete ManyToMany Relationship // UserToWeek relationship = KitchenDutyActiveObjectHelper.findRelationship(activeObjects, user, week); if (relationship != null) { activeObjects.delete(relationship); } return null; } }); return Response.ok().build(); }
Example #7
Source File: KitchenDutyPlanningResource.java From kitchen-duty-plugin-for-atlassian-jira with MIT License | 5 votes |
@GET @Path("/week/{weekNumber}/users") @Produces({MediaType.APPLICATION_JSON}) @AnonymousAllowed public Response getUsersForWeek(@PathParam("weekNumber") final Integer weekNumber) { Week week = activeObjects.executeInTransaction(new TransactionCallback<Week>() { @Override public Week doInTransaction() { Week[] weeks = activeObjects.find(Week.class, Query.select().where("WEEK = ?", weekNumber)); if (weeks != null && weeks.length > 0) { return weeks[0]; } return null; } }); List<KitchenDutyPlanningResourceUserModel> users = new ArrayList<>(); if (week != null) { UserToWeek[] relationships = activeObjects.executeInTransaction(new TransactionCallback<UserToWeek[]>() { @Override public UserToWeek[] doInTransaction() { return KitchenDutyActiveObjectHelper.findAllRelationships(activeObjects, week); } }); if (relationships != null) { for (UserToWeek userToWeek : relationships) { users.add(new KitchenDutyPlanningResourceUserModel(userToWeek.getUser().getID(), userToWeek.getUser().getName())); } } } return Response.ok(users).build(); }
Example #8
Source File: KitchenDutyPlanningResource.java From kitchen-duty-plugin-for-atlassian-jira with MIT License | 5 votes |
@GET @Path("/week/{weekNumber}/users") @Produces({MediaType.APPLICATION_JSON}) @AnonymousAllowed public Response getUsersForWeek(@PathParam("weekNumber") final Integer weekNumber) { // AUTHENTICATION if (!this.isUserLoggedIn()) { return getUnauthorizedErrorResponse(); } // AUTHORIZATION if (this.isUserNotAdmin()) { return getForbiddenErrorResponse(); } // BUSINESS LOGIC Week week = activeObjects.executeInTransaction(new TransactionCallback<Week>() { @Override public Week doInTransaction() { Week[] weeks = activeObjects.find(Week.class, Query.select().where("WEEK = ?", weekNumber)); if (weeks != null && weeks.length > 0) { return weeks[0]; } return null; } }); List<KitchenDutyPlanningResourceUserModel> users = new ArrayList<>(); if (week != null) { UserToWeek[] relationships = activeObjects.executeInTransaction(new TransactionCallback<UserToWeek[]>() { @Override public UserToWeek[] doInTransaction() { return KitchenDutyActiveObjectHelper.findAllRelationships(activeObjects, week); } }); if (relationships != null) { for (UserToWeek userToWeek : relationships) { users.add(new KitchenDutyPlanningResourceUserModel(userToWeek.getUser().getID(), userToWeek.getUser().getName())); } } } return Response.ok(users).build(); }
Example #9
Source File: KitchenDutyActiveObjectHelper.java From kitchen-duty-plugin-for-atlassian-jira with MIT License | 5 votes |
public static Week getWeekByWeekNumberInTransaction(ActiveObjects activeObjects, Long weekNumber) { return activeObjects.executeInTransaction(new TransactionCallback<Week>() { @Override public Week doInTransaction() { Week[] weeks = activeObjects.find(Week.class, Query.select().where("WEEK = ?", weekNumber)); if (weeks != null && weeks.length > 0) { return weeks[0]; } return null; } }); }
Example #10
Source File: UserConfigDao.java From stash-token-auth with GNU General Public License v3.0 | 5 votes |
/** * Updates the list of users to add a new one, if it does not already exist. * * @param username */ @SuppressWarnings("unchecked") private void updateUserList(final String username) { transactionTemplate.execute(new TransactionCallback<Object>() { public Object doInTransaction() { PluginSettings settings = pluginSettingsFactory.createGlobalSettings(); List<String> list = getUserList(); list.add(username); list = newArrayList(newHashSet(list)); settings.put(USER_LIST, list); return null; } }); }
Example #11
Source File: UserConfigDao.java From stash-token-auth with GNU General Public License v3.0 | 5 votes |
public void setUserConfig(final String username, final UserConfig config) { transactionTemplate.execute(new TransactionCallback<UserConfig>() { public UserConfig doInTransaction() { PluginSettings settings = pluginSettingsFactory.createGlobalSettings(); settings.put(BASE + "." + username + ".token", config.getToken()); updateUserList(username); return config; } }); }
Example #12
Source File: AdminConfigResource.java From stash-token-auth with GNU General Public License v3.0 | 5 votes |
@PUT @Consumes(MediaType.APPLICATION_JSON) public Response put(final AdminConfig config, @Context HttpServletRequest request) { final UserProfile user = userManager.getRemoteUser(); if (user == null || !userManager.isSystemAdmin(user.getUserKey())) { return Response.status(Status.UNAUTHORIZED).build(); } transactionTemplate.execute(new TransactionCallback<Object>() { @Override public Object doInTransaction() { AdminConfig current = adminDao.getAdminConfig(); //if the server secret changes, we need to invalidate all tokens if (!Objects.equals(current.getKey(), config.getKey())) { log.warn("Server secret was changed, removing all current tokens"); for (UserConfig uc : userDao.getAllUserConfigs()) { uc.setToken(null); userDao.setUserConfig(uc.getUsername(), uc); } } adminDao.setAdminConfig(config); return null; } }); return Response.noContent().build(); }
Example #13
Source File: KitchenDutyPlanningResource.java From kitchen-duty-plugin-for-atlassian-jira with MIT License | 4 votes |
@PUT @Path("/week/{weekNumber}/users") @Produces({MediaType.APPLICATION_JSON}) @AnonymousAllowed public Response addUserToWeek(@PathParam("weekNumber") final Integer weekNumber, final List<KitchenDutyPlanningResourceUserModel> userParams) { // AUTHENTICATION if (!this.isUserLoggedIn()) { return getUnauthorizedErrorResponse(); } // AUTHORIZATION if (this.isUserNotAdmin()) { return getForbiddenErrorResponse(); } // BUSINESS LOGIC activeObjects.executeInTransaction(new TransactionCallback<Void>() { @Override public Void doInTransaction() { // // WEEK // Week week = KitchenDutyActiveObjectHelper.findUniqueWeek(activeObjects, weekNumber); if (week == null) { week = activeObjects.create(Week.class, new DBParam("WEEK", weekNumber)); week.save(); activeObjects.flush(week); } // // CLEANUP EXISTING RELATIONSHIPS // UserToWeek[] existingRelationships = KitchenDutyActiveObjectHelper.findAllRelationships(activeObjects, week); if (existingRelationships != null) { for (UserToWeek existingRelationship : existingRelationships) { activeObjects.delete(existingRelationship); activeObjects.flush(existingRelationship); } } // // USER // for (KitchenDutyPlanningResourceUserModel userParam : userParams) { User user = KitchenDutyActiveObjectHelper.findUniqueUser(activeObjects, userParam.getUsername()); if (user == null) { user = activeObjects.create(User.class, new DBParam("NAME", userParam.getUsername())); user.save(); activeObjects.flush(user); } // // Establish ManyToMany Relationship // UserToWeek relationship = KitchenDutyActiveObjectHelper.findRelationship(activeObjects, user, week); if (relationship == null) { relationship = activeObjects.create(UserToWeek.class); relationship.setUser(user); relationship.setWeek(week); relationship.save(); activeObjects.flush(relationship); } } return null; } }); return Response.ok().build(); }
Example #14
Source File: KitchenDutyPlanningResource.java From kitchen-duty-plugin-for-atlassian-jira with MIT License | 4 votes |
@DELETE @Path("/week/{weekNumber}/users") @Produces({MediaType.APPLICATION_JSON}) @AnonymousAllowed public Response deleteUserFomWeek(@PathParam("weekNumber") final Integer weekNumber, final KitchenDutyPlanningResourceUserModel userParam) { // AUTHENTICATION if (!this.isUserLoggedIn()) { return getUnauthorizedErrorResponse(); } // AUTHORIZATION if (this.isUserNotAdmin()) { return getForbiddenErrorResponse(); } // BUSINESS LOGIC activeObjects.executeInTransaction(new TransactionCallback<Void>() { @Override public Void doInTransaction() { // // WEEK // Week week = KitchenDutyActiveObjectHelper.findUniqueWeek(activeObjects, weekNumber); if (week == null) { // week does not exist => no relation to delete return null; } // // USER // User user = KitchenDutyActiveObjectHelper.findUniqueUser(activeObjects, userParam.getUsername()); if (user == null) { // user does not exist => no relation to delete return null; } // // Delete ManyToMany Relationship // UserToWeek relationship = KitchenDutyActiveObjectHelper.findRelationship(activeObjects, user, week); if (relationship != null) { activeObjects.delete(relationship); } return null; } }); return Response.ok().build(); }
Example #15
Source File: AdminConfigDao.java From stash-token-auth with GNU General Public License v3.0 | 4 votes |
public void setAdminConfig(final AdminConfig config) { transactionTemplate.execute(new TransactionCallback<AdminConfig>() { public AdminConfig doInTransaction() { PluginSettings settings = pluginSettingsFactory.createGlobalSettings(); settings.put(BASE + ".enabled", BooleanUtils.toStringTrueFalse(config.getEnabled())); settings.put(BASE + ".ttl", Integer.toString(config.getTtl())); settings.put(BASE + ".key", config.getKey()); if(config.getAdminPaths() != null) { settings.put(adminPathPrefix, "true"); settings.put(adminPermissions, BooleanUtils.toStringTrueFalse(config.getAdminPaths().getPermissions())); settings.put(adminUsers, BooleanUtils.toStringTrueFalse(config.getAdminPaths().getUsers())); settings.put(adminGroups, BooleanUtils.toStringTrueFalse(config.getAdminPaths().getGroups())); settings.put(adminLogs, BooleanUtils.toStringTrueFalse(config.getAdminPaths().getLogs())); settings.put(adminAllRestApi, BooleanUtils.toStringTrueFalse(config.getAdminPaths().getAllRestApi())); settings.put(adminAllBranchUtilsApi, BooleanUtils.toStringTrueFalse(config.getAdminPaths().getAllBranchUtilsApi())); settings.put(adminAllKeysApi, BooleanUtils.toStringTrueFalse(config.getAdminPaths().getAllKeysApi())); settings.put(adminAllDefaultReviewersApi, BooleanUtils.toStringTrueFalse(config.getAdminPaths().getAllDefaultReviewersApi())); settings.put(adminAllBranchPermissionsApi, BooleanUtils.toStringTrueFalse(config.getAdminPaths().getAllBranchPermissionsApi())); } if(config.getProjectPaths() != null) { settings.put(projectPathPrefix, "true"); settings.put(projectList, BooleanUtils.toStringTrueFalse(config.getProjectPaths().getProjectList())); settings.put(projectPermissions, BooleanUtils.toStringTrueFalse(config.getProjectPaths().getPermissions())); settings.put(projectRepoList, BooleanUtils.toStringTrueFalse(config.getProjectPaths().getRepoList())); } if(config.getRepoPaths() != null) { settings.put(repoPathPrefix, "true"); settings.put(repoPermissions, BooleanUtils.toStringTrueFalse(config.getRepoPaths().getPermissions())); settings.put(repoCommitHistory, BooleanUtils.toStringTrueFalse(config.getRepoPaths().getCommitHistory())); settings.put(repoFiles, BooleanUtils.toStringTrueFalse(config.getRepoPaths().getFiles())); settings.put(repoPullRequests, BooleanUtils.toStringTrueFalse(config.getRepoPaths().getPullRequests())); settings.put(repoParticipants, BooleanUtils.toStringTrueFalse(config.getRepoPaths().getParticipants())); settings.put(repoBranchPermissions, BooleanUtils.toStringTrueFalse(config.getRepoPaths().getBranchPermissions())); settings.put(repoBuildStatus, BooleanUtils.toStringTrueFalse(config.getRepoPaths().getBuildStatus())); settings.put(repoBaseDetails, BooleanUtils.toStringTrueFalse(config.getRepoPaths().getBaseDetails())); } if(config.getSSHPaths() != null) { settings.put(sshPathPrefix, "true"); settings.put(sshUserKeys, BooleanUtils.toStringTrueFalse(config.getSSHPaths().getUserKeys())); settings.put(sshRepoKeys, BooleanUtils.toStringTrueFalse(config.getSSHPaths().getRepoKeys())); } setCache(config); return config; } }); }
Example #16
Source File: KitchenDutyPlanningResource.java From kitchen-duty-plugin-for-atlassian-jira with MIT License | 4 votes |
@PUT @Path("/week/{weekNumber}/users") @Produces({MediaType.APPLICATION_JSON}) @AnonymousAllowed public Response addUserToWeek(@PathParam("weekNumber") final Integer weekNumber, final List<KitchenDutyPlanningResourceUserModel> userParams) { activeObjects.executeInTransaction(new TransactionCallback<Void>() { @Override public Void doInTransaction() { // // WEEK // Week week = KitchenDutyActiveObjectHelper.findUniqueWeek(activeObjects, weekNumber); if (week == null) { week = activeObjects.create(Week.class, new DBParam("WEEK", weekNumber)); week.save(); activeObjects.flush(week); } // // CLEANUP EXISTING RELATIONSHIPS // UserToWeek[] existingRelationships = KitchenDutyActiveObjectHelper.findAllRelationships(activeObjects, week); if (existingRelationships != null) { for (UserToWeek existingRelationship : existingRelationships) { activeObjects.delete(existingRelationship); activeObjects.flush(existingRelationship); } } // // USER // for (KitchenDutyPlanningResourceUserModel userParam : userParams) { User user = KitchenDutyActiveObjectHelper.findUniqueUser(activeObjects, userParam.getUsername()); if (user == null) { user = activeObjects.create(User.class, new DBParam("NAME", userParam.getUsername())); user.save(); activeObjects.flush(user); } // // Establish ManyToMany Relationship // UserToWeek relationship = KitchenDutyActiveObjectHelper.findRelationship(activeObjects, user, week); if (relationship == null) { relationship = activeObjects.create(UserToWeek.class); relationship.setUser(user); relationship.setWeek(week); relationship.save(); activeObjects.flush(relationship); } } return null; } }); return Response.ok().build(); }
Example #17
Source File: KitchenDutyPlanningResource.java From kitchen-duty-plugin-for-atlassian-jira with MIT License | 4 votes |
/** * Add the User to the Week * * @param weekNumber * @return */ @PUT @Path("/week/{weekNumber}/users") @Produces({MediaType.APPLICATION_JSON}) @AnonymousAllowed public Response addUserToWeek(@PathParam("weekNumber") final Integer weekNumber, final KitchenDutyPlanningResourceUserModel userParam) { activeObjects.executeInTransaction(new TransactionCallback<Void>() { @Override public Void doInTransaction() { // // WEEK // Week week = KitchenDutyActiveObjectHelper.findUniqueWeek(activeObjects, weekNumber); if (week == null) { week = activeObjects.create(Week.class, new DBParam("WEEK", weekNumber)); week.save(); } // // USER // User user = KitchenDutyActiveObjectHelper.findUniqueUser(activeObjects, userParam.getUsername()); if (user == null) { user = activeObjects.create(User.class, new DBParam("NAME", userParam.getUsername())); user.save(); } // // Establish ManyToMany Relationship // UserToWeek relationship = KitchenDutyActiveObjectHelper.findRelationship(activeObjects, user, week); if (relationship != null) { // relation already exists return null; } relationship = activeObjects.create(UserToWeek.class); relationship.setUser(user); relationship.setWeek(week); relationship.save(); return null; } }); return Response.ok().build(); }
Example #18
Source File: KitchenDutyPlanningResource.java From kitchen-duty-plugin-for-atlassian-jira with MIT License | 4 votes |
/** * Remove the User from Week * * @param weekNumber * @return */ @DELETE @Path("/week/{weekNumber}/users") @Produces({MediaType.APPLICATION_JSON}) @AnonymousAllowed public Response deleteUserFomWeek(@PathParam("weekNumber") final Integer weekNumber, final KitchenDutyPlanningResourceUserModel userParam) { activeObjects.executeInTransaction(new TransactionCallback<Void>() { @Override public Void doInTransaction() { // // WEEK // Week week = KitchenDutyActiveObjectHelper.findUniqueWeek(activeObjects, weekNumber); if (week == null) { // week does not exist => no relation to delete return null; } // // USER // User user = KitchenDutyActiveObjectHelper.findUniqueUser(activeObjects, userParam.getUsername()); if (user == null) { // user does not exist => no relation to delete return null; } // // Delete ManyToMany Relationship // UserToWeek relationship = KitchenDutyActiveObjectHelper.findRelationship(activeObjects, user, week); if (relationship != null) { activeObjects.delete(relationship); } return null; } }); return Response.ok().build(); }