org.danekja.discussment.db.discussment-db-hibernate3

Implementation of discussment's DAO layer in Hibernate 3.x.

License

License

Categories

Categories

Hibernate Data ORM
GroupId

GroupId

org.danekja.discussment.db
ArtifactId

ArtifactId

discussment-db-hibernate3
Last Version

Last Version

0.9.3
Release Date

Release Date

Type

Type

jar
Description

Description

org.danekja.discussment.db.discussment-db-hibernate3
Implementation of discussment's DAO layer in Hibernate 3.x.
Project URL

Project URL

https://github.com/danekja/discussment
Source Code Management

Source Code Management

https://github.com/danekja/discussment/tree/master

Download discussment-db-hibernate3

How to add to project

<!-- https://jarcasting.com/artifacts/org.danekja.discussment.db/discussment-db-hibernate3/ -->
<dependency>
    <groupId>org.danekja.discussment.db</groupId>
    <artifactId>discussment-db-hibernate3</artifactId>
    <version>0.9.3</version>
</dependency>
// https://jarcasting.com/artifacts/org.danekja.discussment.db/discussment-db-hibernate3/
implementation 'org.danekja.discussment.db:discussment-db-hibernate3:0.9.3'
// https://jarcasting.com/artifacts/org.danekja.discussment.db/discussment-db-hibernate3/
implementation ("org.danekja.discussment.db:discussment-db-hibernate3:0.9.3")
'org.danekja.discussment.db:discussment-db-hibernate3:jar:0.9.3'
<dependency org="org.danekja.discussment.db" name="discussment-db-hibernate3" rev="0.9.3">
  <artifact name="discussment-db-hibernate3" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.danekja.discussment.db', module='discussment-db-hibernate3', version='0.9.3')
)
libraryDependencies += "org.danekja.discussment.db" % "discussment-db-hibernate3" % "0.9.3"
[org.danekja.discussment.db/discussment-db-hibernate3 "0.9.3"]

Dependencies

provided (2)

Group / Artifact Type Version
org.danekja.discussment : discussment-core jar 0.9.3
org.hibernate : hibernate-core jar 3.6.10.Final

Project Modules

There are no modules declared in this project.

discussment

Library providing discussion/comment functionality to your application with simple interface.

Readme: discussment-core

The library creates basic services for the discussion.

dependencies and environment

Access to the database is solved via JPA. JPA currently uses the MySQL database, which is set in persistence.xml. For this reason, it is necessary to have a MySQL database installed.

Used dependencies:

  • Hibernate 5.2.6.Final

  • MySQL Connector 6.0.5

build steps

  • In persistence.xml, you must set the database url, user, and his password.

  • In the discussion-core folder where the pom.xml file is located, run command mvn install.

  • The resulting jar file is stored in a local maven repository.

how-to use core

The service package have interfaces that provides core services. The default implementation of services is in the service.imp package.

The service package contains these interfaces:

  • CategoryService contains methods for working with categories in a forum.

  • DiscussionService contains methods for working with discussions such as creating a separate discussion or a discussion in a topic.

  • PostService contains methods for working with posts in the discussion.

  • TopicService contains methods for working with topics in the forum.

  • UserService contains methods for working with users who are in the discussion.

The services need an interface to access the database, which is located in the dao package. The default implementation of services is in the dao.imp package. If you need your own access, you need to implement this interface.

using JPA 2.0

The default implementation of DAOs uses JPA 2.1 and its EntityManager. To use it with JPA 2.0, active transaction check using EntityManager's isJoinedToTransaction method needs to be bypassed. For that purpose, there are two classes implementing ITransactionHelper interface.

All the DAOs have GenericDaoJPA class as their common parent. The EntityManager is injected to GenericDaoJPA using its constructor. In the constructor, a new instance of a transaction helper is created as well using the EntityManager - JPA21TransactionHelper is used by default. However, the helper in use can be reset later using a setter.

Below, a sample configuration of a Spring application using JPA 2.0 is outlined:

<bean id="discussmentTransactionHelper" class="org.danekja.discussment.core.dao.jpa.transaction.JPA20TransactionHelper"/>
<bean id="discussmentGenericDao" class="org.danekja.discussment.core.dao.jpa.GenericDaoJPA">
  <constructor-arg name="em" ref="entityManager"/>
  <property name="transactionHelper" ref="discussmentTransactionHelper"/>
</bean>

access control

The accesscontrol package contains the new implementation of user's permissions. The default implementation of services is in the service.impl package.

The authentication mechanism works in similar fashion as general Spring Security user authentication with UserDetails and UserDetailsService interfaces. The library receives user information from the application via defined interfaces (see below) and assignes own permission model for them.

Library methods for permission management contain granular configuration of access to each action (add, remove, view) and item (category, topic, discussion, post). Can be used as-is or the application which uses this library may implement own management on top of the provided functions e.g. to make permissions compliant with the application's roles.

The domain package contains this interface:

  • IDiscussionUser represents the user entity in the context of this library. Any application using this library will have to implement this! Usually the interface should be implemented by the application's User entity and its methods delegated to User's properties.

The service package contains these interfaces:

  • DiscussionUserService contains basic methods to obtain user object from application. Any application using this library will have to implement this! The library presumes the application has own authentication mechanism. This interface should take advantage of that mechanism and provide currently logged-in user.

  • PermissionManagementService contains methods for adding or changing user's permissions.

    • for example using this method will give user permissions for discussion in given topic. PermissionData have values sorted create, delete, edit, view.
      configureDiscussionPermissions(IDiscussionUser user, Topic topic, PermissionData permissions);
      
    • example usage in application.
      permissionService.configureDiscussionPermissions(user, topicService.getTopicById(3), new PermissionData(true, false, false, true);
      
      • will give user permissions to create and view discussions in topic of id 3.
  • AccessControlService contains methods for checking currently logged user's permissions. Has two main usages.

    • guards the core services so user without sufficient permissions can't use requested method. The method then throws AccessDeniedException.
       @Override
          public Topic getTopicById(long topicId) throws AccessDeniedException {
              Topic t = topicDao.getById(topicId);
              if (accessControlService.canViewTopics(t.getCategory())) {
                  return t;
              } else {
                  throw new AccessDeniedException(Action.VIEW, getCurrentUserId(), topicId, PermissionType.TOPIC);
              }
          }
      
    • checks if user has sufficient permissions for viewing certain ui components(for example deleting a topic)
      private Link createRemoveLink(final IModel<Topic> tm) {
      ...
         @Override
         protected void onConfigure() {
            super.onConfigure();
            setVisible(accessControlService.canRemoveTopic(tm.getObject()));
         }
      }
      
  • AccessControlManagerService contains methods for checking another user's permissions.

    • example usage in application
      accessControlManagerService.canRemoveDiscussion(userService.getUserById(5), discussionService.getDiscussionById(2))
      
      • will check if user of id 5 has permissions to remove discussion of id 2.

The services need an interface to access the database, which is located in the dao package. The default implementation of services is in the dao.imp package.

Readme: discussment-ui-wicket

The library creates UI for the discussion. The discussion may be under the article or as a separate forum.

dependencies

The library uses a discussion-core and the wicket library to create UI. The bootstrap library is used for styling html.

Used dependencies:

  • discussment-core 1.0-SNAPSHOT

  • Wicket Core 7.6.0

build steps

  • Before the translation, the discussion-core library must be stored in the local maven repository.

  • In the discussion-ui-wicket folder where the pom.xml file is located, run command mvn install.

  • The resulting jar file is stored in a local maven repository.

how-to use ui-wicket

The library contains these packages:

  • form contains forms such as adding a new category to the forum.

  • list contains panels that create parts of the user interface. The panels use other the panels to create a larger unit. For example, CategoryListPanel, which displays categories and topics, uses TopicListPanel to display topics.

  • model contains classes for data acquisition. Classes can be used as a parameter for creating a ListView instance.

  • panel contains the DiscussionPanel and ForumPanel classes that are ready to be used in a application.

DiscussionPanel creates a panel which contains a discussion. This panel can be used below a article like a discussion about the article. The panel contains an input field for adding a new post and listing all posts and their replies.

ForumPanel creates a panel that contains a forum. The forum is ready for use on a separate page. The panel manages category and topics with discussions. The user can create categories and topics according to their own needs, where forum users can create discussions.

Readme: discussment-example

The example shows a simple use of the discussion-ui-wicket library.

  • How to add a user with his permissions to the discussion.
  • How to use the DiscussionPanel below a article.
  • How to use ForumPanel as a seperate forum.

dependencies

Used dependencies:

  • discussment-ui-wicket 1.0-SNAPSHOT

build steps

  • Before the compile, it is necessary to have discussion-core and discussions-ui-wicket installed in the local maven repository.

  • Run command mvn tomcat7:run in the discussment-example folder where pom.xml is located.

  • Command mvn tomcat7:run runs compile source codes and creates a war file that deploy in Tomcat. The example runs on web address: localhost:8080/discussment-example/

Versions

Version
0.9.3
0.9.2
0.9.1