ensured deployment is stopped, if application cannot be read
This commit is contained in:
@ -22,6 +22,7 @@ import de.muehlencord.shared.account.util.AccountPU;
|
||||
import de.muehlencord.shared.account.util.Permission;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import javax.ejb.Stateless;
|
||||
import javax.inject.Inject;
|
||||
@ -45,11 +46,14 @@ public class ApplicationPermissionControl implements Serializable {
|
||||
@Inject
|
||||
@AccountPU
|
||||
EntityManager em;
|
||||
|
||||
|
||||
@Inject
|
||||
ApplicationEntity application;
|
||||
|
||||
public List<ApplicationPermissionEntity> getApplicationPermissions(ApplicationEntity app) {
|
||||
if (application == null) {
|
||||
return Collections.EMPTY_LIST;
|
||||
}
|
||||
Query query = em.createNamedQuery("ApplicationPermissionEntity.findAll");
|
||||
query.setParameter("application", app);
|
||||
List<ApplicationPermissionEntity> permissionList = query.getResultList();
|
||||
@ -124,34 +128,38 @@ public class ApplicationPermissionControl implements Serializable {
|
||||
|
||||
@Transactional
|
||||
public void setupPermissions(List<Permission> permissions) {
|
||||
for (Permission permission : permissions) {
|
||||
ApplicationPermissionEntity existingPermission = findByName(application, permission.getName());
|
||||
if (existingPermission == null) {
|
||||
// permission not available, create it
|
||||
LOGGER.info("missing permission {} of {}", permission.getName(), application.getApplicationName());
|
||||
existingPermission = new ApplicationPermissionEntity(permission.getName(), permission.getDescription());
|
||||
existingPermission.setApplication(application);
|
||||
em.persist(existingPermission);
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("missing permission {} added to {}", permission.getName(), application.getApplicationName());
|
||||
}
|
||||
} else {
|
||||
if (existingPermission.getPermissionDescription().equals(permission.getDescription())) {
|
||||
if (application == null) {
|
||||
LOGGER.error("Application not initialized, cannot setup permissions");
|
||||
} else {
|
||||
for (Permission permission : permissions) {
|
||||
ApplicationPermissionEntity existingPermission = findByName(application, permission.getName());
|
||||
if (existingPermission == null) {
|
||||
// permission not available, create it
|
||||
LOGGER.info("missing permission {} of {}", permission.getName(), application.getApplicationName());
|
||||
existingPermission = new ApplicationPermissionEntity(permission.getName(), permission.getDescription());
|
||||
existingPermission.setApplication(application);
|
||||
em.persist(existingPermission);
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("Permission {} for {} already exists, skipping", permission.getName(), application.getApplicationName());
|
||||
LOGGER.debug("missing permission {} added to {}", permission.getName(), application.getApplicationName());
|
||||
}
|
||||
} else {
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("description of permssion {} for {} differs, resetting to orignal value {}", permission.getName(), application.getApplicationName(), permission.getDescription());
|
||||
}
|
||||
|
||||
existingPermission.setPermissionDescription(permission.getDescription());
|
||||
em.merge (existingPermission);
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("updated permission description {} for {}", permission.getName(), application.getApplicationName());
|
||||
}
|
||||
if (existingPermission.getPermissionDescription().equals(permission.getDescription())) {
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("Permission {} for {} already exists, skipping", permission.getName(), application.getApplicationName());
|
||||
}
|
||||
} else {
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("description of permssion {} for {} differs, resetting to orignal value {}", permission.getName(), application.getApplicationName(), permission.getDescription());
|
||||
}
|
||||
|
||||
existingPermission.setPermissionDescription(permission.getDescription());
|
||||
em.merge(existingPermission);
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("updated permission description {} for {}", permission.getName(), application.getApplicationName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -46,9 +46,9 @@ public class StartupBean {
|
||||
LOGGER.info("Starting application {}", application.getApplicationName());
|
||||
String instanceName = configService.getConfigValue("base.instance", "Development System", true);
|
||||
LOGGER.info("instanceName={}", instanceName);
|
||||
|
||||
|
||||
// ensure maxFailedLogins is available
|
||||
configService.getConfigValue("account.maxFailedLogins", "5", true);
|
||||
configService.getConfigValue("account.maxFailedLogins", "5", true);
|
||||
|
||||
LOGGER.info("Application startup complete");
|
||||
} catch (ConfigException ex) {
|
||||
@ -59,13 +59,12 @@ public class StartupBean {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@PreDestroy
|
||||
public void shutdown() {
|
||||
LOGGER.info("Shutting down application {}", application.getApplicationName());
|
||||
|
||||
|
||||
LOGGER.info("Application shutdown complete");
|
||||
LOGGER.info("Shutting down application {}", application.getApplicationName());
|
||||
|
||||
LOGGER.info("Application shutdown complete");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -76,13 +76,13 @@ public class ApplicationController {
|
||||
version = "??";
|
||||
buildDate = "??";
|
||||
uuid = null;
|
||||
LOGGER.error("Application id not readable, application will not be able to run");
|
||||
throw new RuntimeException("Application id not readable, application will not be able to run");
|
||||
}
|
||||
|
||||
if (uuid != null) {
|
||||
this.application = applicationService.findById(uuid);
|
||||
if (application == null) {
|
||||
LOGGER.error("Could not find application with id ");
|
||||
throw new RuntimeException("ApplicationId "+uuid.toString()+" not readable, application will not be able to run. You need to setup application in account database first.");
|
||||
} else {
|
||||
LOGGER.info("Found application {} with id {}", application.getApplicationName(), uuid.toString());
|
||||
}
|
||||
@ -91,7 +91,7 @@ public class ApplicationController {
|
||||
|
||||
/**
|
||||
* needs to return link to "Account UI" and not to current selected application
|
||||
* TODO: ensure only Account UI can call functions where appliction can be handed in - all other applications need to call the function which use the injected application
|
||||
* TODO: ensure only Account UI can call functions where application can be handed in - all other applications need to call the function which use the injected application
|
||||
*/
|
||||
@Produces
|
||||
public ApplicationEntity getApplication() {
|
||||
|
||||
Reference in New Issue
Block a user