@Override public List<Map<String, Object>> prepareReferences(long id) { log.debug().message("Get all related objects"); List<Map<String, Object>> refer = new ArrayList<Map<String, Object>>(); Map<String, Object> table = new HashMap<String, Object>(); BrokerService broker = brokerServiceDAO.find(id); if (broker.getServers().size() > 0) { table.put("title", "brokerservice.server.references"); table.put("refObject", "server"); table.put("headers", new String[] {"sName", "sAddress"}); table.put("values", broker.getServers()); refer.add(table); } if (broker.getTransfers().size() > 0) { table = new HashMap<String, Object>(); table.put("title", "brokerservice.transfer.references"); table.put("refObject", "transfer"); table.put("headers", new String[] {"tName", "sourceLocation.lName", "targetLocation.lName"}); table.put("values", broker.getTransfers()); refer.add(table); } return refer; }
@Override public void save(BrokerService broker) { if (broker.getBsId() > 0) { log.debug().message("Saving broker data in database", broker.getBsId()); brokerServiceDAO.update(broker); } else { log.debug().message("Adding new broker"); brokerServiceDAO.save(broker); } }
@Override public String[][] getAll() { List<BrokerService> allBrokerServices = brokerServiceDAO.findAll(); String[][] brokerServices = new String[allBrokerServices.size()][4]; int id = 0; for (BrokerService server : allBrokerServices) { brokerServices[id][0] = Long.toString(server.getBsId()); brokerServices[id][1] = server.getBsName(); brokerServices[id][2] = server.getBsWsdlUrl(); brokerServices[id][3] = canDelete(server.getBsId()) ? "true" : "false"; id++; } return brokerServices; }
@Override public boolean canDelete(long id) { // check if there are releated locations BrokerService broker = brokerServiceDAO.find(id); int serverUses = broker.getServers().size(); int transferUses = broker.getTransfers().size(); if (serverUses > 0) { log.info() .message("Broker can't be deleted as there are {} servers related to it.", serverUses); return false; } else if (transferUses > 0) { log.info() .message( "Broker can't be deleted as there are {} transfers related to it.", transferUses); return false; } return true; }