Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Riina Antikainen
/
Moya
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit fd914ee5
authored
Feb 08, 2014
by
Antti Tönkyrä
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Initial support for ActionLog tags
1 parent
a925af00
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
167 additions
and
0 deletions
code/MoyaBeans/ejbModule/fi/codecrew/moya/beans/ActionLogBean.java
code/MoyaBeans/ejbModule/fi/codecrew/moya/facade/ActionLogMessageTagFacade.java
code/MoyaDatabase/src/fi/codecrew/moya/model/ActionLogMessage.java
code/MoyaDatabase/src/fi/codecrew/moya/model/ActionLogMessageTag.java
code/MoyaWeb/src/fi/codecrew/moya/web/cdiview/actionlog/ActionLogCreateView.java
code/MoyaBeans/ejbModule/fi/codecrew/moya/beans/ActionLogBean.java
View file @
fd914ee
package
fi
.
codecrew
.
moya
.
beans
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.List
;
...
...
@@ -9,6 +10,7 @@ import javax.ejb.EJB;
import
javax.ejb.Stateless
;
import
fi.codecrew.moya.facade.ActionLogFacade
;
import
fi.codecrew.moya.facade.ActionLogMessageTagFacade
;
import
fi.codecrew.moya.beans.ActionLogBeanLocal
;
import
fi.codecrew.moya.beans.PermissionBeanLocal
;
import
fi.codecrew.moya.beans.RoleBeanLocal
;
...
...
@@ -16,6 +18,7 @@ import fi.codecrew.moya.enums.ActionLogMessageState;
import
fi.codecrew.moya.enums.apps.ContentPermission
;
import
fi.codecrew.moya.model.ActionLogMessage
;
import
fi.codecrew.moya.model.ActionLogMessageResponse
;
import
fi.codecrew.moya.model.ActionLogMessageTag
;
import
fi.codecrew.moya.model.Role
;
/**
...
...
@@ -36,12 +39,20 @@ public class ActionLogBean implements ActionLogBeanLocal {
@EJB
private
PermissionBeanLocal
permissionBean
;
@EJB
private
ActionLogMessageTagFacade
actionLogMessageTagFacade
;
@EJB
private
EventBean
eventBean
;
public
ActionLogBean
()
{
// TODO Auto-generated constructor stub
}
@RolesAllowed
(
ContentPermission
.
S_MANAGE_ACTIONLOG
)
public
void
createActionLogEvent
(
String
message
,
Role
crew
,
boolean
isTask
)
{
ArrayList
<
ActionLogMessageTag
>
almts
=
resolveTags
(
message
);
ActionLogMessage
alm
=
new
ActionLogMessage
();
alm
.
setCrew
(
crew
);
if
(
isTask
)
{
...
...
@@ -98,4 +109,62 @@ public class ActionLogBean implements ActionLogBeanLocal {
if
(!
alm
.
getLanEvent
().
equals
(
permissionBean
.
getCurrentUser
().
getEvent
()))
return
null
;
else
return
alm
;
}
private
ArrayList
<
ActionLogMessageTag
>
resolveTags
(
String
message
)
{
ArrayList
<
ActionLogMessageTag
>
almts
=
new
ArrayList
<>();
StringBuilder
sb
=
null
;
boolean
rflag
=
false
;
char
ch
;
for
(
int
i
=
0
;
i
<
message
.
length
();
i
++)
{
if
(
rflag
)
{
if
((
ch
=
message
.
charAt
(
i
))
!=
' '
)
{
sb
.
append
(
ch
);
}
else
{
if
(
sb
.
length
()
>
0
)
{
ActionLogMessageTag
almt
=
getActionLogMessageTagByString
(
sb
.
toString
());
if
(!
almts
.
contains
(
almt
))
{
almts
.
add
(
almt
);
}
}
rflag
=
false
;
sb
=
null
;
}
}
else
if
(!
rflag
)
{
if
(
message
.
charAt
(
i
)
==
'#'
)
{
rflag
=
true
;
sb
=
new
StringBuilder
();
}
}
}
if
(
sb
!=
null
&&
sb
.
length
()
>
0
)
{
ActionLogMessageTag
almt
=
getActionLogMessageTagByString
(
sb
.
toString
());
if
(!
almts
.
contains
(
almt
))
{
almts
.
add
(
almt
);
}
}
return
almts
;
}
private
ActionLogMessageTag
getActionLogMessageTagByString
(
String
s
)
{
s
=
s
.
toLowerCase
();
ActionLogMessageTag
almt
=
null
;
if
((
almt
=
actionLogMessageTagFacade
.
findByTagStringInEvent
(
s
,
eventBean
.
getCurrentEvent
()))
==
null
)
{
almt
=
new
ActionLogMessageTag
();
almt
.
setEvent
(
eventBean
.
getCurrentEvent
());
almt
.
setTag
(
s
);
almt
=
actionLogMessageTagFacade
.
create
(
almt
);
System
.
out
.
println
(
"creating tag: "
+
s
);
return
almt
;
}
else
{
System
.
out
.
println
(
"re-using tag: "
+
s
);
return
almt
;
}
}
}
\ No newline at end of file
code/MoyaBeans/ejbModule/fi/codecrew/moya/facade/ActionLogMessageTagFacade.java
0 → 100644
View file @
fd914ee
package
fi
.
codecrew
.
moya
.
facade
;
import
javax.ejb.LocalBean
;
import
javax.ejb.Stateless
;
import
javax.persistence.TypedQuery
;
import
javax.persistence.criteria.CriteriaBuilder
;
import
javax.persistence.criteria.CriteriaQuery
;
import
javax.persistence.criteria.Root
;
import
fi.codecrew.moya.model.ActionLogMessageTag
;
import
fi.codecrew.moya.model.ActionLogMessageTag_
;
import
fi.codecrew.moya.model.LanEvent
;
@Stateless
@LocalBean
public
class
ActionLogMessageTagFacade
extends
IntegerPkGenericFacade
<
ActionLogMessageTag
>
{
public
ActionLogMessageTagFacade
()
{
super
(
ActionLogMessageTag
.
class
);
}
public
ActionLogMessageTag
findByTagStringInEvent
(
String
tagString
,
LanEvent
event
)
{
CriteriaBuilder
cb
=
getEm
().
getCriteriaBuilder
();
CriteriaQuery
<
ActionLogMessageTag
>
cq
=
cb
.
createQuery
(
ActionLogMessageTag
.
class
);
Root
<
ActionLogMessageTag
>
root
=
cq
.
from
(
ActionLogMessageTag
.
class
);
cq
.
where
(
cb
.
and
(
cb
.
equal
(
root
.
get
(
ActionLogMessageTag_
.
event
),
event
),
cb
.
equal
(
root
.
get
(
ActionLogMessageTag_
.
tag
),
tagString
)
)
);
TypedQuery
<
ActionLogMessageTag
>
tq
=
getEm
().
createQuery
(
cq
);
ActionLogMessageTag
almt
;
try
{
almt
=
tq
.
getSingleResult
();
}
catch
(
Exception
e
)
{
return
null
;
}
return
almt
;
}
}
code/MoyaDatabase/src/fi/codecrew/moya/model/ActionLogMessage.java
View file @
fd914ee
...
...
@@ -10,6 +10,8 @@ import javax.persistence.Entity;
import
javax.persistence.EnumType
;
import
javax.persistence.Enumerated
;
import
javax.persistence.JoinColumn
;
import
javax.persistence.JoinTable
;
import
javax.persistence.ManyToMany
;
import
javax.persistence.OneToMany
;
import
javax.persistence.OrderBy
;
import
javax.persistence.Table
;
...
...
@@ -49,6 +51,18 @@ public class ActionLogMessage extends GenericEntity {
@OrderBy
(
"id"
)
private
List
<
ActionLogMessageResponse
>
actionLogMessageResponses
=
new
ArrayList
<
ActionLogMessageResponse
>();
@ManyToMany
()
@JoinTable
(
name
=
"actionlog_message_tag_sets"
,
joinColumns
=
{
@JoinColumn
(
name
=
"actionlog_message_id"
,
referencedColumnName
=
ActionLogMessage
.
ID_COLUMN
)
},
inverseJoinColumns
=
{
@JoinColumn
(
name
=
"actionlog_message_tag_id"
,
referencedColumnName
=
ActionLogMessageTag
.
ID_COLUMN
)
}
)
private
List
<
ActionLogMessageTag
>
parents
=
new
ArrayList
<
ActionLogMessageTag
>();
@Column
(
name
=
"state"
,
nullable
=
true
)
@Enumerated
(
EnumType
.
STRING
)
private
ActionLogMessageState
state
;
...
...
code/MoyaDatabase/src/fi/codecrew/moya/model/ActionLogMessageTag.java
0 → 100644
View file @
fd914ee
package
fi
.
codecrew
.
moya
.
model
;
import
javax.persistence.Column
;
import
javax.persistence.Entity
;
import
javax.persistence.JoinColumn
;
import
javax.persistence.Table
;
import
org.eclipse.persistence.annotations.OptimisticLocking
;
import
org.eclipse.persistence.annotations.OptimisticLockingType
;
import
org.eclipse.persistence.annotations.PrivateOwned
;
@Entity
@Table
(
name
=
"actionlog_message_tags"
)
@OptimisticLocking
(
type
=
OptimisticLockingType
.
CHANGED_COLUMNS
)
public
class
ActionLogMessageTag
extends
GenericEntity
{
private
static
final
long
serialVersionUID
=
-
2902547412412000488L
;
@Column
(
name
=
"tag"
,
nullable
=
false
)
private
String
tag
;
@JoinColumn
(
name
=
"event"
)
private
LanEvent
event
;
public
LanEvent
getEvent
()
{
return
event
;
}
public
void
setEvent
(
LanEvent
lanEvent
)
{
this
.
event
=
lanEvent
;
}
public
void
setTag
(
String
tag
)
{
this
.
tag
=
tag
;
}
public
String
getTag
()
{
return
tag
;
}
}
code/MoyaWeb/src/fi/codecrew/moya/web/cdiview/actionlog/ActionLogCreateView.java
View file @
fd914ee
...
...
@@ -56,6 +56,7 @@ public class ActionLogCreateView extends GenericCDIView {
}
public
String
send
()
{
actionLogBean
.
createActionLogEvent
(
message
,
role
,
task
);
return
"success"
;
}
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment