private void addDummyData() throws IOException, EntityExistsException, EntityNotFoundException { LOGGER.warn("Add dummy data to database, which could overwrite existing data"); final DummyData dummyData = objectMapper.readValue(dummyDataResource.getFile(), DummyData.class); // User final List<User> users = dummyData.getUsers(); for (User user : users) { userService.save(user); LOGGER.info("User '{}' created", user.getUsername()); } // Gateway final List<Gateway> gateways = dummyData.getGateways(); for (Gateway gateway : gateways) { gatewayService.save(gateway); LOGGER.info("Gateway '{}' with id '{}' created", gateway.getName(), gateway.getId()); } // Cluster final List<Cluster> clusters = dummyData.getClusters(); for (Cluster cluster : clusters) { clusterService.save(cluster); LOGGER.info("Cluster '{}' with id '{}' created", cluster.getName(), cluster.getId()); } // Sensor final List<Sensor> sensors = dummyData.getSensors(); for (Sensor sensor : sensors) { sensorService.save(sensor); LOGGER.info("Sensor '{}' with id '{}' created", sensor.getName(), sensor.getId()); } }
private void createAdmin() { LOGGER.info("Create admin user with username '{}'", adminUsername); User admin = userRepository.findOne(adminUsername); if (admin != null) { LOGGER.warn("User '{}' already present in database", admin.getUsername()); if (!userService.isRolePresent(admin, RoleConstants.ROLE_ADMIN)) { LOGGER.warn( "User '{}' does not have the role {}. Adding now", adminUsername, RoleConstants.ROLE_ADMIN); admin.addRole(RoleConstants.ROLE_ADMIN); } } else { admin = new User(adminUsername, adminPassword); admin.addRole(RoleConstants.ROLE_ADMIN); LOGGER.info("Admin user with username '{}' successfully created", admin.getUsername()); } userRepository.save(admin); }