List of usage examples for java.lang Long equals
public boolean equals(Object obj)
From source file:de.sainth.recipe.backend.rest.controller.FoodController.java
@Secured("ROLE_ADMIN") @RequestMapping(value = "{id}", method = RequestMethod.PUT) HttpEntity<Food> update(@PathVariable("id") Long id, @Valid @RequestBody Food food) { if (id.equals(food.getId())) { if (repository.findOne(food.getId()) != null) { repository.save(food);/*from www .jav a 2 s.co m*/ return new ResponseEntity<>(food, HttpStatus.OK); } } return new ResponseEntity<>(HttpStatus.BAD_REQUEST); }
From source file:net.solarnetwork.central.dras.aop.SecurityAspectSupport.java
/** * Force the user ID in a {@link UserAwareFilter} to the current user ID * unless the current user has the specified role. * //from w w w .j a v a 2 s . c om * <p>If more than one role is provided, any role is allowed to match, * i.e. the set of roles is treated as an "or" style match.</p> * * @param filter the filter to modify * @param adminRole the admin role */ protected void enforceFilterUser(final UserAwareFilter filter, final String... adminRole) { // see if we return ALL programs, or just those for the current user boolean admin = currentUserHasRole(adminRole); if (!admin) { // limit to just active user Long currUser = getCurrentUserId(); if (!currUser.equals(filter.getUserId())) { log.debug("Forcing userId to {} in filter {} because user does not have role {}", new Object[] { currUser, filter, adminRole }); filter.setUserId(currUser); } } }
From source file:de.sainth.recipe.backend.rest.controller.UserController.java
@Secured({ "ROLE_USER", "ROLE_ADMIN" }) @RequestMapping(value = "{id}", method = RequestMethod.PUT) HttpEntity<User> update(@PathVariable("id") Long id, @Valid @RequestBody User user) { if (id.equals(user.getId())) { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); RecipeManagerAuthenticationToken token = (RecipeManagerAuthenticationToken) authentication; if (ROLE_ADMIN.name().equals(token.getRole()) || (ROLE_USER.name().equals(token.getRole()) && token.getPrincipal().equals(id))) { if (repository.findOne(user.getId()) != null) { repository.save(user);// www . j a va2 s .c om return new ResponseEntity<>(user, HttpStatus.OK); } } else { return new ResponseEntity<>(HttpStatus.FORBIDDEN); } } return new ResponseEntity<>(HttpStatus.BAD_REQUEST); }
From source file:net.mindengine.oculus.frontend.web.controllers.trm.tasks.AddTaskDependenciesController.java
@Override public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { verifyPermissions(request);/* www. ja v a 2s . c om*/ Long taskId = Long.parseLong(request.getParameter("taskId")); TrmTask task = trmDAO.getTask(taskId); if (task == null) throw new UnexistentResource("Task with id = " + taskId + " doesn't exist"); User user = getUser(request); if (!user.getId().equals(task.getUserId())) { throw new PermissionDeniedException("You are not allowed to change tasks of other users"); } /* * Fetching task dependencies in order to check if there are the same dependencies as in request. * We should avoid dependency coupling. */ Collection<TrmTaskDependency> dependencies = trmDAO.getTaskDependencies(taskId); String refTaskIds[] = request.getParameter("refTaskIds").split(","); for (String strRefTaskId : refTaskIds) { /* * As each task is sent in request starting with 't' letter we need to remove it from here */ Long refTaskId = Long.parseLong(strRefTaskId.substring(1)); if (!refTaskId.equals(taskId)) { if (!contains(dependencies, refTaskId)) { trmDAO.createTaskDependency(taskId, refTaskId); } } } return new ModelAndView(new RedirectView("../grid/edit-task?id=" + taskId)); }
From source file:jp.primecloud.auto.ui.mock.service.MockFarmService.java
@Override public FarmDto getFarm(Long farmNo) { List<FarmDto> dtos = getFarms(null, null); for (FarmDto dto : dtos) { if (farmNo.equals(dto.getFarm().getFarmNo())) { return dto; }/*from w w w .java2 s. co m*/ } return null; }
From source file:de.berlios.jhelpdesk.web.preferences.DisplayListsEditController.java
private boolean isPrefsOwnedByUser(DisplayListsPreferences dlPrefs, User user) { DisplayListsPreferences userDlPrefs = user.getDlPreferences(); Long lafId = dlPrefs.getId(); if (userDlPrefs == null || lafId == null) { return false; }//from www . ja va 2 s . co m return lafId.equals(userDlPrefs.getId()); }
From source file:de.sainth.recipe.backend.rest.controller.RecipeController.java
@Secured({ "ROLE_USER", "ROLE_ADMIN" }) @RequestMapping(value = "{id}", method = RequestMethod.PUT) HttpEntity<Recipe> update(@PathVariable("id") Long id, @Valid @RequestBody Recipe recipe) { if (id.equals(recipe.getId())) { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication instanceof RecipeManagerAuthenticationToken) { RecipeManagerAuthenticationToken token = (RecipeManagerAuthenticationToken) authentication; Recipe existingRecipe = repository.findOne(id); if (existingRecipe != null && (ROLE_ADMIN.name().equals(token.getRole()) || existingRecipe.getAuthor().getId().equals(token.getPrincipal()))) { repository.save(recipe); return new ResponseEntity<>(recipe, HttpStatus.OK); } else { return new ResponseEntity<>(HttpStatus.FORBIDDEN); }/* w w w .ja va2 s . c om*/ } } return new ResponseEntity<>(HttpStatus.BAD_REQUEST); }
From source file:org.agatom.springatom.data.hades.model.NAbstractPersistable.java
@Override public boolean equals(Object other) { final Long id = this.getId(); return this == other || id != null && other instanceof NAbstractPersistable && id.equals(((NAbstractPersistable) other).getId()); }
From source file:com.openteach.diamond.network.waverider.master.DefaultMasterNode.java
@Override public void addCommandHandler(Long command, CommandHandler handler) { if (command == null || command.equals(0L)) { throw new IllegalArgumentException("command must not be null or 0"); }/*from w w w . j av a2 s .c om*/ commandDispatcher.addCommandHandler(command, handler); }
From source file:com.feilong.core.lang.ObjectUtilTest.java
/** * Assert equals.//from w w w . ja va 2s . co m */ @Test public void assertEquals2() { Long a = new Long(1L); Long b = new Long(1L); assertEquals(false, a == b); assertEquals(true, a.equals(b)); User user = new User(1L); List<User> list = toList(// user, new User(1L), new User(new Long(1L))); for (User user2 : list) { LOGGER.debug((user2.getId() == user.getId()) + ""); } }