Skip to content

Commit 6182e02

Browse files
authored
added shareable annotation (#6)
* added shareable annotation * added column 'shareable' * added migration script & updated README * make old attributes deprecated
1 parent 5a72220 commit 6182e02

25 files changed

+393
-71
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

7+
## [0.3.0] - 2018-05-21
8+
9+
### Added
10+
- `@Shareable` annotation share entity instances with other users in any screen
11+
12+
### Change
13+
- BREAKING: Storage format for message record references has been changed. In order to migrate to the new storage format
14+
you have to download `etc/migrate-message-records-to-new-format.zip` from this repository and run it in the [Diagnose Wizard](https://github.com/mariodavid/cuba-component-runtime-diagnose/tree/de284e5cbce19bb02260b59b9dcd133f2729b0e3#diagnose-wizard).
15+
For that to work you have to temporarily add the [runtime-diagnose](https://github.com/mariodavid/cuba-component-runtime-diagnose) app-component to your application.
16+
This script has to run once, will do the migration. After that, the app component can be removed again.
17+
718
## [0.2.0] - 2018-05-09
819

920
### Added

README.md

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@ dependencies {
4242
}
4343
```
4444

45+
### NOTE: Dependency: declarative-controllers
46+
This application component requires `declarative-controllers` as another dependency you have to add to your application.
47+
48+
The reason is, that you need to extend your screen from `AnnotatableAbstractLookup` instead of `AbstractLookup`.
49+
This superclass is part of the app-component: [cuba-component-declarative-controllers](https://github.com/balvi/cuba-component-declarative-controllers).
50+
51+
Technically it is not strictly required to directly add the dependency to `declarative-controllers`, since `user-inbox` already has a dependency on it.
52+
53+
However: since you directly depend on the app component (with extending your classes from `AnnotatableAbstractLookup`),
54+
it is a best practice to explicitly declare the dependency to it.
4555

4656
## Using the inbox as a user
4757

@@ -71,12 +81,37 @@ This screen allows to manually send a message. A message contains a subject and
7181

7282
This feature can sometimes be helpful but oftentimes sending a regular email is not worse.
7383

74-
##### Context-based messages
84+
#### Context-based messages
7585

7686
Therefore there is another option to send a Message. In this case it is a message that is send through the context of a particular entity.
7787

7888
This is comparable of sending a email with a link that points to a particular customer / order etc. in your application together with the information from the sender.
7989

90+
##### Share entity instances
91+
92+
The way to send context-based messages is to use the `@Shareable` annotation. The annotation is used in any Entity browse / editor screen.
93+
94+
Example:
95+
96+
```
97+
@Shareable(listComponent = "customersTable")
98+
public class CustomerBrowse extends AnnotatableAbstractLookup {
99+
}
100+
```
101+
102+
For the `@Shareable` annotation you need to define the list component on which it should add the share button.
103+
Normally this is the `id` of the table you defined in your browse screen.
104+
105+
This annotation will create a button in the buttonsPanel of the table and add the share button after the default CUBA buttons.
106+
107+
The `@Shareable` annotations can be customized through the following attributes:
108+
109+
* `String listComponent` - the id of the list component / table where the button will be added - REQUIRED
110+
* `String buttonId` - the id of the newly created button that will be created ("attachmentBtn" by default)
111+
* `String buttonsPanel` - the id of the buttons panel where the new button will be added ("buttonsPanel" by default)
112+
113+
114+
more information on this topic can be found here: [balvi/declarative-controllers](https://github.com/balvi/cuba-component-declarative-controllers)
80115

81116
### Send system messages (programmatically)
82117

build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ buildscript {
1313
maven {
1414
url "https://dl.bintray.com/balvi/cuba-components"
1515
}
16+
maven {
17+
url "https://dl.bintray.com/mariodavid/cuba-components"
18+
}
1619
}
1720
dependencies {
1821
classpath "com.haulmont.gradle:cuba-plugin:$cubaVersion"
@@ -111,6 +114,7 @@ subprojects {
111114
dependencies {
112115
appComponent("com.haulmont.cuba:cuba-global:$cubaVersion")
113116
appComponent("de.balvi.cuba.declarativecontrollers:declarativecontrollers-global:0.5.0")
117+
appComponent("de.diedavids.cuba.entitysoftreference:entity-soft-reference-global:0.2.0")
114118

115119
}
116120

1.93 KB
Binary file not shown.

modules/core/db/init/hsql/10.create-db.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ create table DDCUI_MESSAGE (
1212
SENDER_ID varchar(36),
1313
RECEIVER_ID varchar(36) not null,
1414
SUBJECT varchar(255),
15+
SHAREABLE varchar(255),
1516
ENTITY_REFERENCE_ID varchar(255),
1617
ENTITY_REFERENCE_CLASS varchar(255),
1718
ENTITY_CAPTION varchar(255),
@@ -21,4 +22,4 @@ create table DDCUI_MESSAGE (
2122
--
2223
primary key (ID)
2324
)^
24-
-- end DDCUI_MESSAGE
25+
-- end DDCUI_MESSAGE
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
alter table DDCUI_MESSAGE add column SHAREABLE varchar(255) ;

modules/core/src/de/diedavids/cuba/userinbox/service/MessageServiceBean.groovy

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ class MessageServiceBean implements MessageService {
2020
@Inject
2121
UserSessionSource userSessionSource
2222

23-
@Inject
24-
Security security
25-
26-
2723
@Override
2824
void sendSystemMessage(User receiver, String subject, String messageText, Entity entityReference) {
2925
sendMessageFromUser(null, receiver, subject, messageText, entityReference)
@@ -42,7 +38,7 @@ class MessageServiceBean implements MessageService {
4238
protected void sendMessageFromUser(User sender, User receiver, String subject, String messageText, Entity entityReference = null) {
4339
Message message = createMessageInstance()
4440

45-
setRecordToMessage(entityReference, message)
41+
message.shareable = entityReference
4642

4743
message.sender = sender
4844
message.receiver = receiver
@@ -57,12 +53,6 @@ class MessageServiceBean implements MessageService {
5753
metadata.create(Message)
5854
}
5955

60-
protected void setRecordToMessage(Entity entityReference, Message message) {
61-
message.entityReferenceClass = entityReference.metaClass.name
62-
message.entityReferenceId = entityReference.id as String
63-
message.entityCaption = entityReference.instanceName
64-
}
65-
6656
private User getCurrentUser() {
6757
userSessionSource.userSession.currentOrSubstitutedUser
6858
}

modules/core/web/WEB-INF/web.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<!--Application components-->
1414
<context-param>
1515
<param-name>appComponents</param-name>
16-
<param-value>com.haulmont.cuba de.balvi.cuba.declarativecontrollers</param-value>
16+
<param-value>com.haulmont.cuba de.balvi.cuba.declarativecontrollers de.diedavids.cuba.entitysoftreference</param-value>
1717
</context-param>
1818
<listener>
1919
<listener-class>com.haulmont.cuba.core.sys.AppContextLoader</listener-class>

modules/global/src/de/diedavids/cuba/userinbox/app-component.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
22
<app-component xmlns="http://schemas.haulmont.com/cuba/app-component.xsd"
3-
dependsOn="de.balvi.cuba.declarativecontrollers, com.haulmont.cuba">
3+
dependsOn="de.diedavids.cuba.entitysoftreference, de.balvi.cuba.declarativecontrollers, com.haulmont.cuba">
44
<module blocks="*"
55
name="global">
66
<artifact appJar="true"

modules/global/src/de/diedavids/cuba/userinbox/entity/Message.java

Lines changed: 53 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
11
package de.diedavids.cuba.userinbox.entity;
22

3+
import com.haulmont.chile.core.annotations.MetaProperty;
34
import com.haulmont.cuba.core.entity.StandardEntity;
4-
import com.haulmont.cuba.core.entity.annotation.Listeners;
5-
import com.haulmont.cuba.core.entity.annotation.Lookup;
6-
import com.haulmont.cuba.core.entity.annotation.LookupType;
5+
import com.haulmont.cuba.core.entity.annotation.*;
6+
import com.haulmont.cuba.core.global.AppBeans;
7+
import com.haulmont.cuba.core.global.UserSessionSource;
78
import com.haulmont.cuba.security.entity.User;
9+
import de.diedavids.cuba.entitysoftreference.EntitySoftReferenceConverter;
810

9-
import javax.persistence.Column;
10-
import javax.persistence.Entity;
11-
import javax.persistence.FetchType;
12-
import javax.persistence.JoinColumn;
13-
import javax.persistence.Lob;
14-
import javax.persistence.ManyToOne;
15-
import javax.persistence.Table;
16-
import javax.persistence.Temporal;
17-
import javax.persistence.TemporalType;
11+
import javax.annotation.PostConstruct;
12+
import javax.persistence.*;
1813
import javax.validation.constraints.NotNull;
1914
import java.util.Date;
15+
import de.diedavids.cuba.entitysoftreference.EntitySoftReferenceDatatype;
2016

2117
@Listeners("ddcui_MessageEntityListener")
2218
@Table(name = "DDCUI_MESSAGE")
@@ -37,15 +33,38 @@ public class Message extends StandardEntity {
3733
@Column(name = "SUBJECT")
3834
protected String subject;
3935

36+
37+
@SystemLevel
38+
@Convert(converter = EntitySoftReferenceConverter.class)
39+
@MetaProperty(datatype = "EntitySoftReference")
40+
@Column(name = "SHAREABLE")
41+
protected com.haulmont.cuba.core.entity.Entity shareable;
42+
43+
/**
44+
* @deprecated use Message.shareable instead
45+
*/
46+
@Deprecated
47+
@SystemLevel
4048
@Column(name = "ENTITY_REFERENCE_ID")
4149
protected String entityReferenceId;
4250

51+
/**
52+
* @deprecated use Message.shareable instead
53+
*/
54+
@Deprecated
55+
@SystemLevel
4356
@Column(name = "ENTITY_REFERENCE_CLASS")
4457
protected String entityReferenceClass;
4558

59+
/**
60+
* @deprecated use Message.shareable instead
61+
*/
62+
@Deprecated
63+
@SystemLevel
4664
@Column(name = "ENTITY_CAPTION")
4765
protected String entityCaption;
4866

67+
4968
@Lob
5069
@Column(name = "TEXT")
5170
protected String text;
@@ -59,6 +78,15 @@ public class Message extends StandardEntity {
5978
@Column(name = "RECEIVED_AT", nullable = false)
6079
protected Date receivedAt;
6180

81+
public void setShareable(com.haulmont.cuba.core.entity.Entity shareable) {
82+
this.shareable = shareable;
83+
}
84+
85+
public com.haulmont.cuba.core.entity.Entity getShareable() {
86+
return shareable;
87+
}
88+
89+
6290
public void setReceivedAt(Date receivedAt) {
6391
this.receivedAt = receivedAt;
6492
}
@@ -136,4 +164,17 @@ public User getReceiver() {
136164
}
137165

138166

167+
168+
@PostConstruct
169+
protected void initSender() {
170+
setSender(getCurrentUser());
171+
}
172+
173+
private User getCurrentUser() {
174+
return getUserSessionSource().getUserSession().getCurrentOrSubstitutedUser();
175+
}
176+
177+
private UserSessionSource getUserSessionSource() {
178+
return AppBeans.get(UserSessionSource.class);
179+
}
139180
}

0 commit comments

Comments
 (0)