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;
|
||||||
@ -50,6 +51,9 @@ public class ApplicationPermissionControl implements Serializable {
|
|||||||
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,6 +128,9 @@ public class ApplicationPermissionControl implements Serializable {
|
|||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public void setupPermissions(List<Permission> permissions) {
|
public void setupPermissions(List<Permission> permissions) {
|
||||||
|
if (application == null) {
|
||||||
|
LOGGER.error("Application not initialized, cannot setup permissions");
|
||||||
|
} else {
|
||||||
for (Permission permission : permissions) {
|
for (Permission permission : permissions) {
|
||||||
ApplicationPermissionEntity existingPermission = findByName(application, permission.getName());
|
ApplicationPermissionEntity existingPermission = findByName(application, permission.getName());
|
||||||
if (existingPermission == null) {
|
if (existingPermission == null) {
|
||||||
@ -146,7 +153,7 @@ public class ApplicationPermissionControl implements Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
existingPermission.setPermissionDescription(permission.getDescription());
|
existingPermission.setPermissionDescription(permission.getDescription());
|
||||||
em.merge (existingPermission);
|
em.merge(existingPermission);
|
||||||
if (LOGGER.isDebugEnabled()) {
|
if (LOGGER.isDebugEnabled()) {
|
||||||
LOGGER.debug("updated permission description {} for {}", permission.getName(), application.getApplicationName());
|
LOGGER.debug("updated permission description {} for {}", permission.getName(), application.getApplicationName());
|
||||||
}
|
}
|
||||||
@ -154,4 +161,5 @@ public class ApplicationPermissionControl implements Serializable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -64,7 +64,6 @@ public class StartupBean {
|
|||||||
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