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 de.muehlencord.shared.account.util.Permission;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.ejb.Stateless;
|
import javax.ejb.Stateless;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
@ -45,11 +46,14 @@ public class ApplicationPermissionControl implements Serializable {
|
|||||||
@Inject
|
@Inject
|
||||||
@AccountPU
|
@AccountPU
|
||||||
EntityManager em;
|
EntityManager em;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
ApplicationEntity application;
|
ApplicationEntity application;
|
||||||
|
|
||||||
public List<ApplicationPermissionEntity> getApplicationPermissions(ApplicationEntity app) {
|
public List<ApplicationPermissionEntity> getApplicationPermissions(ApplicationEntity app) {
|
||||||
|
if (application == null) {
|
||||||
|
return Collections.EMPTY_LIST;
|
||||||
|
}
|
||||||
Query query = em.createNamedQuery("ApplicationPermissionEntity.findAll");
|
Query query = em.createNamedQuery("ApplicationPermissionEntity.findAll");
|
||||||
query.setParameter("application", app);
|
query.setParameter("application", app);
|
||||||
List<ApplicationPermissionEntity> permissionList = query.getResultList();
|
List<ApplicationPermissionEntity> permissionList = query.getResultList();
|
||||||
@ -124,34 +128,38 @@ public class ApplicationPermissionControl implements Serializable {
|
|||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public void setupPermissions(List<Permission> permissions) {
|
public void setupPermissions(List<Permission> permissions) {
|
||||||
for (Permission permission : permissions) {
|
if (application == null) {
|
||||||
ApplicationPermissionEntity existingPermission = findByName(application, permission.getName());
|
LOGGER.error("Application not initialized, cannot setup permissions");
|
||||||
if (existingPermission == null) {
|
} else {
|
||||||
// permission not available, create it
|
for (Permission permission : permissions) {
|
||||||
LOGGER.info("missing permission {} of {}", permission.getName(), application.getApplicationName());
|
ApplicationPermissionEntity existingPermission = findByName(application, permission.getName());
|
||||||
existingPermission = new ApplicationPermissionEntity(permission.getName(), permission.getDescription());
|
if (existingPermission == null) {
|
||||||
existingPermission.setApplication(application);
|
// permission not available, create it
|
||||||
em.persist(existingPermission);
|
LOGGER.info("missing permission {} of {}", permission.getName(), application.getApplicationName());
|
||||||
if (LOGGER.isDebugEnabled()) {
|
existingPermission = new ApplicationPermissionEntity(permission.getName(), permission.getDescription());
|
||||||
LOGGER.debug("missing permission {} added to {}", permission.getName(), application.getApplicationName());
|
existingPermission.setApplication(application);
|
||||||
}
|
em.persist(existingPermission);
|
||||||
} else {
|
|
||||||
if (existingPermission.getPermissionDescription().equals(permission.getDescription())) {
|
|
||||||
if (LOGGER.isDebugEnabled()) {
|
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 {
|
} else {
|
||||||
if (LOGGER.isDebugEnabled()) {
|
if (existingPermission.getPermissionDescription().equals(permission.getDescription())) {
|
||||||
LOGGER.debug("description of permssion {} for {} differs, resetting to orignal value {}", permission.getName(), application.getApplicationName(), permission.getDescription());
|
if (LOGGER.isDebugEnabled()) {
|
||||||
}
|
LOGGER.debug("Permission {} for {} already exists, skipping", permission.getName(), application.getApplicationName());
|
||||||
|
}
|
||||||
existingPermission.setPermissionDescription(permission.getDescription());
|
} else {
|
||||||
em.merge (existingPermission);
|
if (LOGGER.isDebugEnabled()) {
|
||||||
if (LOGGER.isDebugEnabled()) {
|
LOGGER.debug("description of permssion {} for {} differs, resetting to orignal value {}", permission.getName(), application.getApplicationName(), permission.getDescription());
|
||||||
LOGGER.debug("updated permission description {} for {}", permission.getName(), application.getApplicationName());
|
}
|
||||||
}
|
|
||||||
|
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());
|
LOGGER.info("Starting application {}", application.getApplicationName());
|
||||||
String instanceName = configService.getConfigValue("base.instance", "Development System", true);
|
String instanceName = configService.getConfigValue("base.instance", "Development System", true);
|
||||||
LOGGER.info("instanceName={}", instanceName);
|
LOGGER.info("instanceName={}", instanceName);
|
||||||
|
|
||||||
// ensure maxFailedLogins is available
|
// ensure maxFailedLogins is available
|
||||||
configService.getConfigValue("account.maxFailedLogins", "5", true);
|
configService.getConfigValue("account.maxFailedLogins", "5", true);
|
||||||
|
|
||||||
LOGGER.info("Application startup complete");
|
LOGGER.info("Application startup complete");
|
||||||
} catch (ConfigException ex) {
|
} catch (ConfigException ex) {
|
||||||
@ -59,13 +59,12 @@ public class StartupBean {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@PreDestroy
|
@PreDestroy
|
||||||
public void shutdown() {
|
public void shutdown() {
|
||||||
LOGGER.info("Shutting down application {}", application.getApplicationName());
|
LOGGER.info("Shutting down application {}", application.getApplicationName());
|
||||||
|
|
||||||
|
LOGGER.info("Application shutdown complete");
|
||||||
LOGGER.info("Application shutdown complete");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -76,13 +76,13 @@ public class ApplicationController {
|
|||||||
version = "??";
|
version = "??";
|
||||||
buildDate = "??";
|
buildDate = "??";
|
||||||
uuid = null;
|
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) {
|
if (uuid != null) {
|
||||||
this.application = applicationService.findById(uuid);
|
this.application = applicationService.findById(uuid);
|
||||||
if (application == null) {
|
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 {
|
} else {
|
||||||
LOGGER.info("Found application {} with id {}", application.getApplicationName(), uuid.toString());
|
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
|
* 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
|
@Produces
|
||||||
public ApplicationEntity getApplication() {
|
public ApplicationEntity getApplication() {
|
||||||
|
|||||||
Reference in New Issue
Block a user