use of javax.validation.Valid in project zhcet-web by zhcet-amu.
the class PasswordResetController method savePassword.
@PostMapping
@PreAuthorize("hasAuthority('PASSWORD_CHANGE_PRIVILEGE')")
public String savePassword(@Valid PasswordReset passwordReset, BindingResult bindingResult, RedirectAttributes redirectAttributes) {
Optional<User> optionalUser = Auditor.getLoggedInAuthentication().map(Authentication::getPrincipal).filter(principal -> !principal.getClass().isAssignableFrom(User.class)).map(principal -> ((User) principal).getUserId()).flatMap(userService::findById);
if (!optionalUser.isPresent()) {
redirectAttributes.addAttribute("error", "Unknown Error");
} else {
User user = optionalUser.get();
if (bindingResult.hasErrors()) {
redirectAttributes.addFlashAttribute("password", passwordReset);
redirectAttributes.addFlashAttribute("org.springframework.validation.BindingResult.password", bindingResult);
} else {
try {
passwordResetService.resetPassword(user, passwordReset);
redirectAttributes.addFlashAttribute("reset_success", true);
return "redirect:/login";
} catch (TokenValidationException tve) {
log.warn("Token Verification : Password Reset : {}", tve.getMessage());
redirectAttributes.addAttribute("error", tve.getMessage());
} catch (PasswordValidationException pve) {
log.debug("Password Verification Exception", pve);
redirectAttributes.addFlashAttribute("pass_errors", pve.getMessage());
}
}
}
return String.format("redirect:/login/password/reset?hash=%s&auth=%s", passwordReset.getHash(), passwordReset.getToken());
}
use of javax.validation.Valid in project oc-explorer by devgateway.
the class AwardsWonLostController method procurementsWonLost.
@ApiOperation(value = "Counts the won, lost procurements, flags and amounts. Receives any filters, " + "but most important here is the supplierId and bidderId. Requires bid extension. Use bidderId instead " + "of supplierId.")
@RequestMapping(value = "/api/procurementsWonLost", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json")
public List<ProcurementsWonLost> procurementsWonLost(@ModelAttribute @Valid final YearFilterPagingRequest filter) {
Assert.notEmpty(filter.getBidderId(), "bidderId must not be empty!");
Assert.isTrue(CollectionUtils.isEmpty(filter.getSupplierId()), "supplierId is not allowed here! Use bidderId to show results!");
// supplier is the same thing as bidder for this particular query
filter.setSupplierId(filter.getBidderId());
Map<String, CriteriaDefinition> noSupplierCriteria = createDefaultFilterCriteriaMap(filter);
noSupplierCriteria.remove(MongoConstants.Filters.SUPPLIER_ID);
Aggregation agg1 = newAggregation(match(getYearDefaultFilterCriteria(filter, noSupplierCriteria, TENDER_PERIOD_START_DATE)), unwind("bids.details"), unwind("bids.details.tenderers"), match(getYearDefaultFilterCriteria(filter, noSupplierCriteria, TENDER_PERIOD_START_DATE)), group(BIDS_DETAILS_TENDERERS_ID).count().as("count").sum(BIDS_DETAILS_VALUE_AMOUNT).as("totalAmount").sum(FLAGS_TOTAL_FLAGGED).as("countFlags"), project("count", "totalAmount", "countFlags"));
List<CountAmountFlags> applied = releaseAgg(agg1, CountAmountFlags.class);
Aggregation agg2 = newAggregation(match(where(AWARDS_STATUS).is(Award.Status.active.toString()).andOperator(getYearDefaultFilterCriteria(filter, TENDER_PERIOD_START_DATE))), unwind("awards"), unwind("awards.suppliers"), match(where(AWARDS_STATUS).is(Award.Status.active.toString()).andOperator(getYearDefaultFilterCriteria(filter.awardFiltering(), TENDER_PERIOD_START_DATE))), group(MongoConstants.FieldNames.AWARDS_SUPPLIERS_ID).count().as("count").sum(MongoConstants.FieldNames.AWARDS_VALUE_AMOUNT).as("totalAmount").sum(FLAGS_TOTAL_FLAGGED).as("countFlags"), project("count", "totalAmount", "countFlags"));
List<CountAmountFlags> won = releaseAgg(agg2, CountAmountFlags.class);
ArrayList<ProcurementsWonLost> ret = new ArrayList<>();
applied.forEach(a -> {
ProcurementsWonLost r = new ProcurementsWonLost();
r.setApplied(a);
Optional<CountAmountFlags> optWon = won.stream().filter(w -> w.getId().equals(a.getId())).findFirst();
if (optWon.isPresent()) {
r.setWon(optWon.get());
r.setLostAmount(r.getApplied().getTotalAmount().subtract(r.getWon().getTotalAmount()));
r.setLostCount(r.getApplied().getCount() - r.getWon().getCount());
} else {
r.setLostAmount(r.getApplied().getTotalAmount());
r.setLostCount(r.getLostCount());
}
ret.add(r);
});
return ret;
}
use of javax.validation.Valid in project cxf by apache.
the class BookStoreFeed method getBooks.
@GET
@Path("/books/feed")
@NotNull
@Valid
@Produces("application/atom+xml")
public AtomFeed getBooks() {
final AtomFeed feed = new AtomFeed();
for (final Book book : service.all()) {
final AtomFeedEntry entry = new AtomFeedEntry();
entry.addLink("/bookstore/books/" + book.getId());
feed.addEntry(entry);
}
return feed;
}
use of javax.validation.Valid in project OsmAnd-tools by osmandapp.
the class GpxController method attachSrtm.
@PostMapping(path = { "/process-srtm" }, produces = "application/json")
public ResponseEntity<StreamingResponseBody> attachSrtm(@RequestPart(name = "file") @Valid @NotNull @NotEmpty MultipartFile file) throws IOException {
GPXFile gpxFile = GPXUtilities.loadGPXFile(file.getInputStream());
GPXFile srtmGpx = calculateSrtmAltitude(gpxFile, null);
StreamingResponseBody responseBody = outputStream -> {
GPXUtilities.writeGpx(new OutputStreamWriter(outputStream), srtmGpx, IProgress.EMPTY_PROGRESS);
};
return ResponseEntity.ok().header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + file.getName()).contentType(MediaType.APPLICATION_XML).body(responseBody);
}
use of javax.validation.Valid in project gravitee-management-rest-api by gravitee-io.
the class ConfigurationResourceTest method shouldGetApplicationRoles.
@Test
public void shouldGetApplicationRoles() throws TechnicalException {
resetAllMocks();
RoleEntity appRoleEntity = new RoleEntity();
appRoleEntity.setDefaultRole(true);
appRoleEntity.setName("appRole");
appRoleEntity.setSystem(false);
when(roleService.findByScope(RoleScope.APPLICATION)).thenReturn(Collections.singletonList(appRoleEntity));
final Response response = target().path("applications").path("roles").request().get();
assertEquals(HttpStatusCode.OK_200, response.getStatus());
final ConfigurationApplicationRolesResponse appRoles = response.readEntity(ConfigurationApplicationRolesResponse.class);
assertNotNull(appRoles);
@Valid List<ApplicationRole> roles = appRoles.getData();
assertNotNull(roles);
assertEquals(1, roles.size());
assertEquals("appRole", roles.get(0).getId());
assertEquals(true, roles.get(0).getDefault());
assertEquals("appRole", roles.get(0).getName());
assertEquals(false, roles.get(0).getSystem());
}
Aggregations