@Post @Path("/apps") @Permission(value = {Role.ADMIN, Role.MEMBER}) public void create(Apps apps, UploadedFile war) { try { PropertiesUtil props = new PropertiesUtil("src/main/resources/path.properties"); String pathDeploy = props.getValor("tomcat.webapps"); if (war != null) apps.setNameWar(war.getFileName().substring(0, war.getFileName().indexOf("."))); validator.validate(apps); uploadValidate(war); validator.onErrorUsePageOf(this).newApps(); File warFile = new File(pathDeploy + war.getFileName()); IOUtils.copyLarge(war.getFile(), new FileOutputStream(warFile)); apps.setUser(this.userSession.getUser()); this.result.include("message", "Upload concluído com sucesso."); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } repository.create(apps); result.redirectTo(this).index(); }
@Get @Path("/apps/{apps.id}/edit") @Permission(value = {Role.ADMIN, Role.MEMBER}) public Apps edit(Apps apps) { checkPermission(apps); return repository.find(apps.getId()); }
@Delete @Path("/apps/{apps.id}") @Permission(value = {Role.ADMIN, Role.MEMBER}) public void destroy(Apps apps) { checkPermission(apps); repository.destroy(repository.find(apps.getId())); result.redirectTo(this).index(); }
@Put @Path("/apps") @Permission(value = {Role.ADMIN, Role.MEMBER}) public void update(Apps apps) { checkPermission(apps); apps.setUser(this.userSession.getUser()); validator.validate(apps); validator.onErrorUsePageOf(this).edit(apps); repository.update(apps); result.redirectTo(this).index(); }
@Get @Path("apps/list/{apps.id}") @Permission(value = {Role.ADMIN, Role.MEMBER}) public List<Apps> list(Apps apps) { return repository.findById(apps.getId()); }
private void checkPermission(Apps apps) { if (apps.getUser().getRole() != Role.ADMIN && apps.getUser().getId() != userSession.getUser().getId()) { result.redirectTo(IndexController.class).negado(); } }
@Get @Path("/apps/{apps.id}") @Permission(value = {Role.ADMIN, Role.MEMBER}) public Apps show(Apps apps) { return repository.find(apps.getId()); }