CCM NG: Shortcuts module now deploys successfully

git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4147 8810af33-2d31-482b-a856-94f89814c4df
pull/2/head
jensp 2016-06-09 09:40:09 +00:00
parent 572db42a15
commit e4f8ca3b97
11 changed files with 122 additions and 82 deletions

View File

@ -36,6 +36,9 @@
<Logger name="org.libreccm.core.AbstractEntityRepository"
level="debug">
</Logger>
<Logger name="org.libreccm.modules.CcmIntegrator"
level="debug">
</Logger>
<Logger name="org.libreccm.security.OneTimeAuthTokenCleaner"
level="debug">
</Logger>

View File

@ -98,6 +98,15 @@ public class CcmIntegrator implements Integrator {
final List<TreeNode> tree = treeManager.generateTree(modules);
final List<TreeNode> orderedNodes = treeManager.orderModules(tree);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Ordered list of modules:");
orderedNodes.forEach(m -> {
LOGGER.debug("\t{}-{}",
m.getModuleInfo().getModuleName(),
m.getModuleInfo().getModuleVersion());
});
}
// //Get DataSource and Connection from the sessionFactory of
// //Hibernate.
final DataSource dataSource = (DataSource) sessionFactory.
@ -119,6 +128,9 @@ public class CcmIntegrator implements Integrator {
//Migrate the modules
for (final TreeNode node : orderedNodes) {
LOGGER.debug("Applying migrations for module {}-{}",
node.getModuleInfo().getModuleName(),
node.getModuleInfo().getModuleVersion());
migrateModule(node.getModule().getClass(), dataSource);
// for (Class<?> entity : node.getModuleInfo().getModuleEntities()) {
@ -190,8 +202,7 @@ public class CcmIntegrator implements Integrator {
* @param buffer Buffer for the location string.
* @param connection The JDBC connection object.
*
* @throws SQLException If an error occurs while accessing the
* database.
* @throws SQLException If an error occurs while accessing the database.
* @throws IntegrationException If the database is not supported yet.
*/
private void appendDbLocation(final StringBuffer buffer,

View File

@ -19,6 +19,7 @@
package org.libreccm.modules;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

View File

@ -0,0 +1,50 @@
/*
* Copyright (C) 2016 LibreCCM Foundation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package org.libreccm.security;
import javax.persistence.EntityManager;
import org.libreccm.shortcuts.ShortcutsConstants;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public class ShortcutsRolesSetup {
private final EntityManager entityManager;
public ShortcutsRolesSetup(final EntityManager entityManager) {
this.entityManager = entityManager;
}
public void setupShortcutsRoles() {
final Role shortcutsManager = new Role();
shortcutsManager.setName("shortcuts-manager");
entityManager.persist(shortcutsManager);
final Permission permission = new Permission();
permission.setGrantee(shortcutsManager);
permission.setGrantedPrivilege(
ShortcutsConstants.SHORTSCUT_MANAGE_PRIVILEGE);
permission.setObject(null);
entityManager.persist(permission);
}
}

View File

@ -18,10 +18,12 @@
*/
package org.libreccm.shortcuts;
import org.libreccm.core.CcmCore;
import org.libreccm.modules.CcmModule;
import org.libreccm.modules.InitEvent;
import org.libreccm.modules.InstallEvent;
import org.libreccm.modules.Module;
import org.libreccm.modules.RequiredModule;
import org.libreccm.modules.ShutdownEvent;
import org.libreccm.modules.UnInstallEvent;
import org.libreccm.web.ApplicationType;
@ -30,7 +32,11 @@ import org.libreccm.web.ApplicationType;
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@Module(applicationTypes = {
@Module(
requiredModules = {
@RequiredModule(module = CcmCore.class)
},
applicationTypes = {
@ApplicationType(name = ShortcutsConstants.SHORTCUTS_APP_TYPE,
descBundle = "org.libreccm.shortcuts.ShortcutsResources",
singleton = true,

View File

@ -35,4 +35,6 @@ public final class ShortcutsConstants {
*/
public static final String SHORTCUTS_PRIMARY_URL = "/shortcuts/";
public static final String SHORTSCUT_MANAGE_PRIVILEGE = "manage_shortcuts";
}

View File

@ -18,16 +18,12 @@
*/
package org.libreccm.shortcuts;
import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.modules.InstallEvent;
import org.libreccm.security.PermissionManager;
import org.libreccm.security.Role;
import org.libreccm.security.RoleManager;
import org.libreccm.security.RoleRepository;
import org.libreccm.web.AbstractCcmApplicationSetup;
import org.libreccm.web.CcmApplication;
import java.util.UUID;
import org.libreccm.security.ShortcutsRolesSetup;
/**
*
@ -47,16 +43,17 @@ public class ShortcutsSetup extends AbstractCcmApplicationSetup {
shortcuts.setPrimaryUrl(ShortcutsConstants.SHORTCUTS_PRIMARY_URL);
getEntityManager().persist(shortcuts);
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final RoleRepository roleRepository = cdiUtil.findBean(
RoleRepository.class);
final Role shortcutsManager = new Role();
shortcutsManager.setName("shortcuts-manager");
roleRepository.save(shortcutsManager);
final ShortcutsRolesSetup rolesSetup = new ShortcutsRolesSetup(
getEntityManager());
rolesSetup.setupShortcutsRoles();
final PermissionManager permissionManager = cdiUtil.findBean(
PermissionManager.class);
permissionManager.grantPrivilege("manage_shortcuts", shortcutsManager);
// final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
// final RoleRepository roleRepository = cdiUtil.findBean(
// RoleRepository.class);
// roleRepository.save(shortcutsManager);
// final PermissionManager permissionManager = cdiUtil.findBean(
// PermissionManager.class);
// permissionManager.grantPrivilege("manage_shortcuts", shortcutsManager);
}
}

View File

@ -1,9 +0,0 @@
create table SHORTCUTS (
shortcut_id bigint generated by default as identity,
redirect varchar(1024),
url_key varchar(1024),
primary key (shortcut_id)
);
alter table CCM_SHORTCUTS.SHORTCUTS
add constraint UK_4otuwtog6qqdbg4e6p8xdpw8h unique (URL_KEY);

View File

@ -1,12 +0,0 @@
create table SHORTCUTS (
shortcut_id number(19,0) not null,
redirect varchar2(1024 char),
url_key varchar2(1024 char),
primary key (shortcut_id)
);
create table SHORTCUTS_APP (
object_id number(19,0) not null,
primary key (object_id)
);

View File

@ -1,9 +0,0 @@
create table SHORTCUTS (
shortcut_id int8 not null,
redirect varchar(1024),
url_key varchar(1024),
primary key (shortcut_id)
);
alter table CCM_SHORTCUTS.SHORTCUTS
add constraint UK_4otuwtog6qqdbg4e6p8xdpw8h unique (URL_KEY);