Commit 22163f10 authored by Roberto Loayza's avatar Roberto Loayza

Lista de Agentes y eliminación de goal y actions

parent 1b9ba02e
...@@ -190,4 +190,17 @@ public class AgentController { ...@@ -190,4 +190,17 @@ public class AgentController {
} }
} }
@GetMapping(value = "/")
@PreAuthorize("hasPermission(this, 'view')")
public ResponseEntity<String> getAgentAll() {
HttpStatus hs = HttpStatus.OK;
try {
return new ResponseEntity<>(gsonBuilder.create().toJson(agentService.getAgentAll()), hs);
} catch (Exception e) {
String info = "Error detectado al obtener informacion";
hs = HttpStatus.INTERNAL_SERVER_ERROR;
return new ResponseEntity<>(gsonBuilder.create().toJson(info), hs);
}
}
} }
...@@ -7,7 +7,6 @@ import com.bytesw.xdf.controller.XDFController; ...@@ -7,7 +7,6 @@ import com.bytesw.xdf.controller.XDFController;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiParam;
import lombok.extern.log4j.Log4j2; import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
...@@ -38,19 +37,7 @@ public class GoalController extends XDFController<GoalBean, Long> { ...@@ -38,19 +37,7 @@ public class GoalController extends XDFController<GoalBean, Long> {
return new ResponseEntity(gson.toJson(info), HttpStatus.OK); return new ResponseEntity(gson.toJson(info), HttpStatus.OK);
} }
@DeleteMapping(value = "/goalForAction/{id}")
@PreAuthorize("hasPermission(this, 'view')")
public ResponseEntity<String> GoalForAction(@ApiParam(value = "id", required = true) @PathVariable("id") Long id) {
String info = "";
try{
goalService.deleteGoalForAction(id);
info = id.toString();
return new ResponseEntity(gson.toJson(info), HttpStatus.OK);
} catch (Exception e) {
info = e.getMessage();
}
return new ResponseEntity(gson.toJson(info), HttpStatus.INTERNAL_SERVER_ERROR);
}
@PutMapping(value = "/goalForAction/{id}") @PutMapping(value = "/goalForAction/{id}")
@PreAuthorize("hasPermission(this, 'edit')") @PreAuthorize("hasPermission(this, 'edit')")
...@@ -92,4 +79,5 @@ public class GoalController extends XDFController<GoalBean, Long> { ...@@ -92,4 +79,5 @@ public class GoalController extends XDFController<GoalBean, Long> {
return new ResponseEntity<>(gsonBuilder.create().toJson(info), hs); return new ResponseEntity<>(gsonBuilder.create().toJson(info), hs);
} }
} }
} }
...@@ -16,5 +16,4 @@ public class GoalForActionController extends XDFController<GoalForActionsBean, L ...@@ -16,5 +16,4 @@ public class GoalForActionController extends XDFController<GoalForActionsBean, L
public GoalForActionController(GoalForActionService service) { public GoalForActionController(GoalForActionService service) {
super(service); super(service);
} }
} }
...@@ -21,4 +21,5 @@ import java.util.List; ...@@ -21,4 +21,5 @@ import java.util.List;
public interface AgentRepository extends CrudRepository<Agent, Long>, JpaSpecificationExecutor<Agent> { public interface AgentRepository extends CrudRepository<Agent, Long>, JpaSpecificationExecutor<Agent> {
List<Agent> findByStatus(AgentStatusEnum status); List<Agent> findByStatus(AgentStatusEnum status);
} }
...@@ -6,6 +6,7 @@ import com.bytesw.bytebot.jdbc.AgentJDBCRepository; ...@@ -6,6 +6,7 @@ import com.bytesw.bytebot.jdbc.AgentJDBCRepository;
import com.bytesw.bytebot.model.enums.*; import com.bytesw.bytebot.model.enums.*;
import com.bytesw.bytebot.repository.*; import com.bytesw.bytebot.repository.*;
import com.bytesw.xdf.config.AppContextManager; import com.bytesw.xdf.config.AppContextManager;
import com.bytesw.xdf.exception.NotFoundException;
import com.bytesw.xdf.sql.beans.Pagination; import com.bytesw.xdf.sql.beans.Pagination;
import lombok.extern.log4j.Log4j2; import lombok.extern.log4j.Log4j2;
import org.apache.camel.ProducerTemplate; import org.apache.camel.ProducerTemplate;
...@@ -507,4 +508,25 @@ public class AgentService extends CustomPaginationService<Agent> { ...@@ -507,4 +508,25 @@ public class AgentService extends CustomPaginationService<Agent> {
} }
} }
public List<Map> getAgentAll() {
List<Agent> lista = (List<Agent>) agentRepository.findAll();
if (lista.size() <= 0) {
throw new NotFoundException("Error al listar agentes.");
}
List<Map> result = new ArrayList<>();
for(Agent agent: lista) {
Map<String, Object> map = new HashMap<>();
map.put("id", agent.getId());
map.put("name", agent.getName());
map.put("description", agent.getDescription());
map.put("version", agent.getVersion());
map.put("status", agent.getStatus().getName());
map.put("period", agent.getPeriod());
map.put("timezone", agent.getTimezone());
result.add(map);
}
return result;
}
} }
package com.bytesw.bytebot.service; package com.bytesw.bytebot.service;
import com.bytesw.bytebot.etl.beans.ActionBean;
import com.bytesw.bytebot.etl.beans.GoalForActionsBean; import com.bytesw.bytebot.etl.beans.GoalForActionsBean;
import com.bytesw.bytebot.etl.dao.ActionRepository; import com.bytesw.bytebot.etl.dao.ActionRepository;
import com.bytesw.bytebot.etl.model.Action; import com.bytesw.bytebot.etl.model.Action;
......
package com.bytesw.bytebot.service; package com.bytesw.bytebot.service;
import com.bytesw.bytebot.etl.beans.GoalBean; import com.bytesw.bytebot.etl.beans.GoalBean;
import com.bytesw.bytebot.etl.model.Goal; import com.bytesw.bytebot.etl.model.Goal;
import com.bytesw.bytebot.etl.model.GoalForActions;
import com.bytesw.bytebot.repository.*; import com.bytesw.bytebot.repository.*;
import com.bytesw.xdf.exception.AlreadyExistsException; import com.bytesw.xdf.exception.AlreadyExistsException;
import com.bytesw.xdf.exception.NotFoundException; import com.bytesw.xdf.exception.NotFoundException;
...@@ -84,12 +84,11 @@ public class GoalService extends XDFService<Goal, GoalBean, Long> { ...@@ -84,12 +84,11 @@ public class GoalService extends XDFService<Goal, GoalBean, Long> {
} }
@Transactional(propagation = Propagation.REQUIRED) @Transactional(propagation = Propagation.REQUIRED)
public void deleteGoalForAction(Long goalId) { @Override
public void delete(Long goalId) {
if (!goalRepository.existsById(goalId)){ if (!goalRepository.existsById(goalId)){
throw new NotFoundException("Goal no registrado."); throw new NotFoundException("Goal no registrado.");
} }
goalForActionService.deleteGoalForAction(goalId); goalForActionService.deleteGoalForAction(goalId);
goalRepository.deleteById(goalId); goalRepository.deleteById(goalId);
} }
...@@ -148,4 +147,5 @@ public class GoalService extends XDFService<Goal, GoalBean, Long> { ...@@ -148,4 +147,5 @@ public class GoalService extends XDFService<Goal, GoalBean, Long> {
} }
return result; return result;
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment