2
0
Fork 0

made first demo almost fully working

This commit is contained in:
Willem Cazander 2012-11-26 16:08:45 +01:00
parent 2a0d992642
commit 01b3b5cc54
104 changed files with 3259 additions and 2181 deletions

View file

@ -9,11 +9,29 @@
<name>vasc-demo-tech-ejb3</name>
<description>vasc-demo-tech-ejb3</description>
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>${javaee-api.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.forwardfire.vasc</groupId>
<artifactId>vasc-core</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.forwardfire.vasc</groupId>
<artifactId>vasc-core-ejb3-client</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>${javaee-api.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.forwardfire.vasc.lib</groupId>
<artifactId>vasc-lib-i18n</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View file

@ -37,9 +37,11 @@ import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
import net.forwardfire.vasc.core.VascController;
import net.forwardfire.vasc.core.VascEntry;
import net.forwardfire.vasc.core.VascEntryAccessType;
import net.forwardfire.vasc.core.VascEntryGroup;
import net.forwardfire.vasc.demo.tech.ejb3.menu.model.VascMenu;
import net.forwardfire.vasc.demo.tech.ejb3.menu.model.VascMenuComparator;
import net.forwardfire.vasc.demo.tech.ejb3.menu.model.VascMenuGroupComparator;
import net.forwardfire.vasc.demo.tech.ejb3.menu.model.VascMenuWebComparator;
import net.forwardfire.vasc.demo.tech.ejb3.menu.model.VascMenuGroup;
import net.forwardfire.vasc.demo.tech.ejb3.menu.model.VascMenuWeb;
@ -54,17 +56,12 @@ import net.forwardfire.vasc.demo.tech.ejb3.menu.model.VascMenuWebType;
public class VascMenuControllerImpl implements VascMenuControllerLocal,VascMenuControllerRemote {
private VascMenuWebComparator vascMenuWebComparator = null;
private VascMenuGroupComparator vascMenuGroupComparator = null;
private VascMenuComparator vascMenuComparator = null;
@Resource
private SessionContext session;
public VascMenuControllerImpl() {
vascMenuWebComparator = new VascMenuWebComparator();
vascMenuGroupComparator = new VascMenuGroupComparator();
vascMenuComparator = new VascMenuComparator();
}
public List<VascMenuWeb> fetchVascMenuWeb() {
@ -104,78 +101,7 @@ public class VascMenuControllerImpl implements VascMenuControllerLocal,VascMenuC
}
return result;
}
public List<VascMenuGroup> fetchVascMenuGroup() {
List<VascMenuGroup> result = new ArrayList<VascMenuGroup>(50);
Connection connection = null;
try {
DataSource ds = getDataSource("openejb:Resource/jdbc/DemoManagerDataDS");
connection = ds.getConnection();
Statement s = connection.createStatement();
s.execute("SELECT * FROM VASC_MENU_GROUP");
ResultSet rs = s.getResultSet();
while (rs.next()) {
VascMenuGroup menu = new VascMenuGroup();
menu.setId(rs.getString(1));
menu.setTitle(rs.getString(2));
menu.setActive(rs.getBoolean(3));
menu.setRoles(rs.getString(4));
menu.setMenuOrder(rs.getInt(5));
if (filterVascMenuRoles(menu.getActive(),menu.getRoles())==false) {
continue;
}
result.add(menu);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (connection!=null) {
try {
connection.close();
} catch (Exception e) {
}
}
}
return result;
}
public List<VascMenu> fetchVascMenu() {
List<VascMenu> result = new ArrayList<VascMenu>(50);
Connection connection = null;
try {
DataSource ds = getDataSource("openejb:Resource/jdbc/DemoManagerDataDS");
connection = ds.getConnection();
Statement s = connection.createStatement();
s.execute("SELECT * FROM VASC_MENU");
ResultSet rs = s.getResultSet();
while (rs.next()) {
VascMenu menu = new VascMenu();
menu.setId(rs.getInt(1));
menu.setVascEntryId(rs.getString(2));
menu.setTitle(rs.getString(3));
menu.setActive(rs.getBoolean(4));
menu.setRoles(rs.getString(5));
menu.setMenuOrder(rs.getInt(6));
menu.setMenuGroup(rs.getString(7));
if (filterVascMenuRoles(menu.getActive(),menu.getRoles())==false) {
continue;
}
result.add(menu);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (connection!=null) {
try {
connection.close();
} catch (Exception e) {
}
}
}
return result;
}
private DataSource getDataSource(String name) throws SQLException {
try {
@ -210,11 +136,28 @@ public class VascMenuControllerImpl implements VascMenuControllerLocal,VascMenuC
}
public List<VascMenuGroup> getFilteredMenuGroup() {
List<VascMenuGroup> result = fetchVascMenuGroup();
for (VascMenuGroup group:result) {
group.setMenus(getFilteredMenu(group.getId()));
VascController vc = null;
try {
Context initialContext = new InitialContext();
vc = (VascController)initialContext.lookup("openejb:Resource/vasc/server-tech");
} catch (Exception e) {
e.printStackTrace();
}
Collections.sort(result,vascMenuGroupComparator);
List<VascMenuGroup> result = new ArrayList<VascMenuGroup>(20);
for (String groupdId:vc.getVascEntryController().getVascEntryGroupIds()) {
VascEntryGroup veg = vc.getVascEntryController().getVascEntryGroupById(groupdId);
if (filterVascMenuRoles(veg.getView(),veg.getRolesView())==false) {
continue;
}
VascMenuGroup group = new VascMenuGroup();
group.setId(veg.getId());
group.setTitleKey(veg.getName());
group.setMenus(getFilteredMenu(group.getId()));
result.add(group);
}
// Collections.sort(result,vascMenuGroupComparator);
return result;
}
@ -222,13 +165,33 @@ public class VascMenuControllerImpl implements VascMenuControllerLocal,VascMenuC
if (groupId==null) {
throw new NullPointerException("Can't filter on null groupId.");
}
List<VascMenu> result = new ArrayList<VascMenu>(15);
for (VascMenu menu:fetchVascMenu()) {
if (groupId.equals(menu.getMenuGroup())) {
result.add(menu);
}
VascController vc = null;
try {
Context initialContext = new InitialContext();
vc = (VascController)initialContext.lookup("openejb:Resource/vasc/server-tech");
} catch (Exception e) {
e.printStackTrace();
}
Collections.sort(result,vascMenuComparator);
List<VascMenu> result = new ArrayList<VascMenu>(15);
for (String vascEntryId:vc.getVascEntryController().getVascEntryByGroupId(groupId)) {
VascEntry ve = vc.getVascEntryController().getVascEntryById(vascEntryId);
if (ve.getAccessType()!=null && (
ve.getAccessType()==VascEntryAccessType.ENTRY_LINK |
ve.getAccessType()==VascEntryAccessType.ENTRY_LIST
)
) {
continue;
}
if (filterVascMenuRoles(ve.getView(),ve.getRolesView())==false) {
continue;
}
VascMenu menu = new VascMenu();
menu.setVascEntryId(ve.getId());
menu.setVascGroupId(ve.getVascGroupId());
menu.setTitleKey(ve.getName());
result.add(menu);
}
// Collections.sort(result,vascMenuComparator);
return result;
}

View file

@ -33,109 +33,43 @@ import java.io.Serializable;
public class VascMenu implements Serializable {
private static final long serialVersionUID = 5087600835051760512L;
private Integer id = null;
private String vascEntryId = null;
private String title = null;
private Boolean active = null;
private String roles = null;
private Integer menuOrder = null;
private String menuGroup = null;
/**
* @return the id
*/
public Integer getId() {
return id;
}
/**
* @param id the id to set
*/
public void setId(Integer id) {
this.id = id;
}
private String titleKey = null;
private String vascGroupId = null;
/**
* @return the vascEntryId
*/
public String getVascEntryId() {
return vascEntryId;
}
/**
* @param vascEntryId the vascEntryId to set
*/
public void setVascEntryId(String vascEntryId) {
this.vascEntryId = vascEntryId;
}
/**
* @return the title
* @return the titleKey
*/
public String getTitle() {
return title;
public String getTitleKey() {
return titleKey;
}
/**
* @param title the title to set
* @param titleKey the titleKey to set
*/
public void setTitle(String title) {
this.title = title;
public void setTitleKey(String titleKey) {
this.titleKey = titleKey;
}
/**
* @return the active
* @return the vascGroupId
*/
public Boolean getActive() {
return active;
public String getVascGroupId() {
return vascGroupId;
}
/**
* @param active the active to set
* @param vascGroupId the vascGroupId to set
*/
public void setActive(Boolean active) {
this.active = active;
}
/**
* @return the roles
*/
public String getRoles() {
return roles;
}
/**
* @param roles the roles to set
*/
public void setRoles(String roles) {
this.roles = roles;
}
/**
* @return the menuOrder
*/
public Integer getMenuOrder() {
return menuOrder;
}
/**
* @param menuOrder the menuOrder to set
*/
public void setMenuOrder(Integer menuOrder) {
this.menuOrder = menuOrder;
}
/**
* @return the menuGroup
*/
public String getMenuGroup() {
return menuGroup;
}
/**
* @param menuGroup the menuGroup to set
*/
public void setMenuGroup(String menuGroup) {
this.menuGroup = menuGroup;
public void setVascGroupId(String vascGroupId) {
this.vascGroupId = vascGroupId;
}
}

View file

@ -1,49 +0,0 @@
/*
* Copyright 2009-2012 forwardfire.net All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.forwardfire.vasc.demo.tech.ejb3.menu.model;
import java.io.Serializable;
import java.util.Comparator;
/**
* VascMenuComparator orders the menu group.
*
* @author Willem Cazander
* @version 1.0 nov 17, 2012
*/
public class VascMenuComparator implements Serializable,Comparator<VascMenu> {
private static final long serialVersionUID = 386631856823832371L;
public int compare(VascMenu m1, VascMenu m2) {
if (m1.getMenuOrder()==null) {
return 1;
}
if (m2.getMenuOrder()==null) {
return -1;
}
return m1.getMenuOrder().compareTo(m2.getMenuOrder());
}
}

View file

@ -35,10 +35,7 @@ public class VascMenuGroup implements Serializable {
private static final long serialVersionUID = -9154803561816570868L;
private String id = null;
private String title = null;
private Boolean active = null;
private String roles = null;
private Integer menuOrder = null;
private String titleKey = null;
private List<VascMenu> menus = null;
/**
@ -54,61 +51,19 @@ public class VascMenuGroup implements Serializable {
public void setId(String id) {
this.id = id;
}
/**
* @return the titleKey
*/
public String getTitleKey() {
return titleKey;
}
/**
* @return the title
* @param titleKey the titleKey to set
*/
public String getTitle() {
return title;
}
/**
* @param title the title to set
*/
public void setTitle(String title) {
this.title = title;
}
/**
* @return the active
*/
public Boolean getActive() {
return active;
}
/**
* @param active the active to set
*/
public void setActive(Boolean active) {
this.active = active;
}
/**
* @return the roles
*/
public String getRoles() {
return roles;
}
/**
* @param roles the roles to set
*/
public void setRoles(String roles) {
this.roles = roles;
}
/**
* @return the menuOrder
*/
public Integer getMenuOrder() {
return menuOrder;
}
/**
* @param menuOrder the menuOrder to set
*/
public void setMenuOrder(Integer menuOrder) {
this.menuOrder = menuOrder;
public void setTitleKey(String titleKey) {
this.titleKey = titleKey;
}
/**

View file

@ -1,49 +0,0 @@
/*
* Copyright 2009-2012 forwardfire.net All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.forwardfire.vasc.demo.tech.ejb3.menu.model;
import java.io.Serializable;
import java.util.Comparator;
/**
* VascMenuGroupComparator orders the menu group.
*
* @author Willem Cazander
* @version 1.0 nov 17, 2012
*/
public class VascMenuGroupComparator implements Serializable,Comparator<VascMenuGroup> {
private static final long serialVersionUID = 386631856823832371L;
public int compare(VascMenuGroup m1, VascMenuGroup m2) {
if (m1.getMenuOrder()==null) {
return 1;
}
if (m2.getMenuOrder()==null) {
return -1;
}
return m1.getMenuOrder().compareTo(m2.getMenuOrder());
}
}

View file

@ -0,0 +1,22 @@
package net.forwardfire.vasc.demo.tech.ejb3.user;
import java.util.List;
import java.util.Locale;
import java.util.Map;
public interface ClientUserController {
String doClientLogin();
Map<String,String> getResourceBundle(Locale locale);
List<Locale> getResourceBundleLocales();
/*
void doClientLogout();
User getUser() throws Exception;
List<RightRole> getClientRoles() throws Exception;
*/
}

View file

@ -1,12 +1,19 @@
package net.forwardfire.vasc.demo.tech.ejb3.user;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.ResourceBundle;
import javax.annotation.Resource;
import javax.annotation.security.RolesAllowed;
import javax.ejb.SessionContext;
import javax.ejb.Stateless;
@Stateless(name="loginUserController")
public class LoginUserControllerImpl implements LoginUserControllerLocal,LoginUserControllerRemote {
import net.forwardfire.vasc.lib.i18n.bundle.RootApplicationBundle;
@Stateless(name="clientUserController")
public class ClientUserControllerImpl implements ClientUserControllerLocal,ClientUserControllerRemote {
@Resource
private SessionContext session;
@ -54,4 +61,22 @@ public class LoginUserControllerImpl implements LoginUserControllerLocal,LoginUs
return u.getUsername();
*/
}
public Map<String,String> getResourceBundle(Locale locale) {
ResourceBundle bundle = ResourceBundle.getBundle(RootApplicationBundle.class.getName(), locale);
if (bundle instanceof RootApplicationBundle) {
RootApplicationBundle appBundle = (RootApplicationBundle)bundle;
return appBundle.getBundleData();
}
throw new IllegalStateException("Loaded bundle: "+bundle+" is not RootApplicationBundle.");
}
public List<Locale> getResourceBundleLocales() {
ResourceBundle bundle = ResourceBundle.getBundle(RootApplicationBundle.class.getName());
if (bundle instanceof RootApplicationBundle) {
RootApplicationBundle appBundle = (RootApplicationBundle)bundle;
return appBundle.getApplicationSupportedLocales();
}
throw new IllegalStateException("Loaded bundle: "+bundle+" is not RootApplicationBundle.");
}
}

View file

@ -3,6 +3,6 @@ package net.forwardfire.vasc.demo.tech.ejb3.user;
import javax.ejb.Local;
@Local
public interface LoginUserControllerLocal extends LoginUserController {
public interface ClientUserControllerLocal extends ClientUserController {
}

View file

@ -3,6 +3,6 @@ package net.forwardfire.vasc.demo.tech.ejb3.user;
import javax.ejb.Remote;
@Remote
public interface LoginUserControllerRemote extends LoginUserController {
public interface ClientUserControllerRemote extends ClientUserController {
}

View file

@ -1,21 +0,0 @@
package net.forwardfire.vasc.demo.tech.ejb3.user;
import java.util.List;
import java.util.Map;
import javax.ejb.Local;
import javax.ejb.Remote;
public interface LoginUserController {
public String doClientLogin();
/*
public void doClientLogout();
public User getUser() throws Exception;
public List<RightRole> getClientRoles() throws Exception;
*/
}