RulePad:


Code:
packageio.hexlet.typoreporter.controller;
importio.hexlet.typoreporter.domain.typo.TypoEvent;
importio.hexlet.typoreporter.service.TypoService;
importio.hexlet.typoreporter.service.WorkspaceService;
importio.hexlet.typoreporter.handler.exception.TypoNotFoundException;
importio.hexlet.typoreporter.handler.exception.WorkspaceNotFoundException;
importlombok.RequiredArgsConstructor;
importlombok.extern.slf4j.Slf4j;
importorg.springframework.stereotype.Controller;
importorg.springframework.web.bind.annotation.PatchMapping;
importorg.springframework.web.bind.annotation.PathVariable;
importorg.springframework.web.bind.annotation.RequestMapping;
importorg.springframework.web.bind.annotation.RequestParam;
importjava.util.Optional;
//TODO add tests@Slf4j@Controller@RequestMapping("/typos")
@RequiredArgsConstructorpublicclassTypoController {
privatefinalTypoServicetypoService;
privatefinalWorkspaceServiceworkspaceService;
@PatchMapping("/{id}/status")
publicStringupdateTypoStatus(@PathVariableLongid,
@RequestParamOptional<Long> wksId,
@RequestParamOptional<TypoEvent> event,
@RequestParamOptional<String> next) {
if (wksId.isEmpty() || !workspaceService.existsWorkspaceById(wksId.get())) {
//TODO send to error pagefinalvare = newWorkspaceNotFoundException(wksId.orElse(0L));
log.error(e.toString(), e);
return"redirect:/workspaces";
}
if (event.isEmpty()) {
//TODO send to error pagelog.error("TypoEvent={} must not be null", event.orElse(null));
return ("redirect:/workspace/") + wksId.get() + next.orElse("/typos");
}
finalvarupdatedTypo = typoService.updateTypoStatus(id, event.get());
if (updatedTypo.isEmpty()) {
//TODO send to error pagefinalvare = newTypoNotFoundException(id);
log.error(e.getMessage(), e);
}
return ("redirect:/workspace/") + wksId.get() + next.orElse("/typos");
}
}[
{
"index": "1724830895",
"title": "Controller class must have a service field",
"description": "Controller class must have service class field to handle business logic processing",
"tags": [],
"checkForFilesFoldersConstraints": "INCLUDE",
"checkForFilesFolders": [
"hexlet-correction/src/main/java/io/hexlet/typoreporter/controller"
],
"processFilesFolders": "WITHIN",
"quantifierXPathQuery": [
"src:unit/src:class"
],
"constraintXPathQuery": [
"src:unit/src:class[src:annotation/src:name[text()=\"Controller\"] and src:specifier[text()=\"public\"] and src:name[substring(text(),string-length(text())-string-length(\"Controller\")+1)=\"Controller\"] and descendant-or-self::src:decl_stmt/src:decl[(src:specifier[text()=\"private\"] and src:specifier[text()=\"final\"] and src:name[substring(text(),string-length(text())-string-length(\"Service\")+1)=\"Service\"])]]"
],
"grammar": "class with declaration statement with ( visibility \"private\" and specifier \"final\" and name \"...Service\" ) must have annotation \"Controller\" and visibility \"public\" and name \"...Controller\" and declaration statement with ( visibility \"private\" and specifier \"final\" and name \"...Service\" )"
}
]
RulePad:


Code:
[ { "index": "1724830895", "title": "Controller class must have a service field", "description": "Controller class must have service class field to handle business logic processing", "tags": [], "checkForFilesFoldersConstraints": "INCLUDE", "checkForFilesFolders": [ "hexlet-correction/src/main/java/io/hexlet/typoreporter/controller" ], "processFilesFolders": "WITHIN", "quantifierXPathQuery": [ "src:unit/src:class" ], "constraintXPathQuery": [ "src:unit/src:class[src:annotation/src:name[text()=\"Controller\"] and src:specifier[text()=\"public\"] and src:name[substring(text(),string-length(text())-string-length(\"Controller\")+1)=\"Controller\"] and descendant-or-self::src:decl_stmt/src:decl[(src:specifier[text()=\"private\"] and src:specifier[text()=\"final\"] and src:name[substring(text(),string-length(text())-string-length(\"Service\")+1)=\"Service\"])]]" ], "grammar": "class with declaration statement with ( visibility \"private\" and specifier \"final\" and name \"...Service\" ) must have annotation \"Controller\" and visibility \"public\" and name \"...Controller\" and declaration statement with ( visibility \"private\" and specifier \"final\" and name \"...Service\" )" } ]