Skip to content

Commit e16c6ad

Browse files
Merge pull request #9 from dynamiatools/3.x
3.2.0
2 parents 8819e8e + f6bfbbd commit e16c6ad

24 files changed

+466
-101
lines changed

sources/api/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@
2626
<parent>
2727
<groupId>tools.dynamia.modules</groupId>
2828
<artifactId>tools.dynamia.modules.saas.parent</artifactId>
29-
<version>3.1.4</version>
29+
<version>3.2.0</version>
3030
</parent>
3131
<artifactId>tools.dynamia.modules.saas.api</artifactId>
3232

3333
<name>DynamiaModules - SaaS API</name>
3434
<url>https://www.dynamia.tools/modules/saas</url>
35-
<version>3.1.4</version>
35+
<version>3.2.0</version>
3636

3737
<build>
3838
<plugins>

sources/api/src/main/java/tools/dynamia/modules/saas/api/AccountAdminAction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919

2020
import tools.dynamia.actions.AbstractAction;
2121
import tools.dynamia.actions.ActionEvent;
22-
import tools.dynamia.actions.ActionFilter;
22+
import tools.dynamia.actions.ActionSelfFilter;
2323
import tools.dynamia.integration.Containers;
2424

25-
public abstract class AccountAdminAction extends AbstractAction implements ActionFilter {
25+
public abstract class AccountAdminAction extends AbstractAction implements ActionSelfFilter {
2626

2727
private boolean authorizationRequired;
2828

sources/core/pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
<parent>
2323
<groupId>tools.dynamia.modules</groupId>
2424
<artifactId>tools.dynamia.modules.saas.parent</artifactId>
25-
<version>3.1.4</version>
25+
<version>3.2.0</version>
2626
</parent>
2727
<artifactId>tools.dynamia.modules.saas</artifactId>
28-
<version>3.1.4</version>
28+
<version>3.2.0</version>
2929
<name>DynamiaModules - SaaS Core</name>
3030
<url>https://www.dynamia.tools/modules/saas</url>
3131

@@ -49,12 +49,12 @@
4949
<dependency>
5050
<groupId>tools.dynamia.modules</groupId>
5151
<artifactId>tools.dynamia.modules.saas.api</artifactId>
52-
<version>3.1.4</version>
52+
<version>3.2.0</version>
5353
</dependency>
5454
<dependency>
5555
<groupId>tools.dynamia.modules</groupId>
5656
<artifactId>tools.dynamia.modules.saas.jpa</artifactId>
57-
<version>3.1.4</version>
57+
<version>3.2.0</version>
5858
</dependency>
5959
<dependency>
6060
<groupId>junit</groupId>

sources/core/src/main/java/tools/dynamia/modules/saas/AccountContext.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import tools.dynamia.integration.Containers;
2525
import tools.dynamia.modules.saas.api.dto.AccountDTO;
2626
import tools.dynamia.modules.saas.domain.Account;
27-
import tools.dynamia.modules.saas.services.AccountService;
2827
import tools.dynamia.web.util.HttpUtils;
2928

3029
import java.util.List;
@@ -37,11 +36,9 @@ public class AccountContext {
3736

3837
private final LoggingService logger = new SLF4JLoggingService(AccountContext.class);
3938

40-
private final AccountService service;
4139
private final List<AccountResolver> resolvers;
4240

43-
public AccountContext(AccountService service, List<AccountResolver> resolvers) {
44-
this.service = service;
41+
public AccountContext(List<AccountResolver> resolvers) {
4542
this.resolvers = resolvers;
4643
}
4744

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package tools.dynamia.modules.saas;
2+
3+
import tools.dynamia.modules.saas.domain.AccountPayment;
4+
5+
import java.util.Map;
6+
7+
/**
8+
* Basic API to implement processing account payments. You should implement
9+
* your own payment processor and register it using spring annotations
10+
* registry.
11+
*/
12+
public interface AccountPaymentProcessor {
13+
14+
String getId();
15+
16+
String getName();
17+
18+
Map<String, Object> processPayment(AccountPayment payment);
19+
}

sources/core/src/main/java/tools/dynamia/modules/saas/AccountSessionHolder.java

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
package tools.dynamia.modules.saas;
2020

21-
import org.springframework.beans.factory.annotation.Autowired;
21+
import com.fasterxml.jackson.annotation.JsonIgnore;
2222
import org.springframework.web.context.annotation.SessionScope;
2323
import org.springframework.web.context.request.RequestAttributes;
2424
import org.springframework.web.context.request.RequestContextHolder;
@@ -41,12 +41,17 @@
4141
public class AccountSessionHolder implements Serializable {
4242

4343

44-
private transient final AccountService service;
44+
@JsonIgnore
45+
private transient AccountService service;
4546

4647
private Locale accountLocale;
47-
private Account current;
48+
private Long currentId;
4849
private AccountDTO currentDTO;
4950

51+
public AccountSessionHolder() {
52+
this.service = Containers.get().findObject(AccountService.class);
53+
}
54+
5055
public AccountSessionHolder(AccountService service) {
5156
this.service = service;
5257
}
@@ -69,19 +74,17 @@ public static AccountSessionHolder get() {
6974
}
7075

7176
public Account getCurrent() {
72-
return current;
77+
return currentId != null ? getService().getAccountById(currentId) : null;
7378
}
7479

7580
public void setCurrent(final Account account) {
7681
if (account != null) {
7782
try {
7883
DomainUtils.lookupCrudService().executeWithinTransaction(() -> {
79-
80-
this.current = service.getAccountById(account.getId());
84+
var current = getService().getAccountById(account.getId());
8185
accountLocale = current.getLocale() != null ? Locale.forLanguageTag(current.getLocale()) : null;
82-
83-
currentDTO = null;
84-
toDTO();
86+
currentId = current.getId();
87+
currentDTO = current.toDTO();
8588
});
8689
} catch (Exception e) {
8790
//ignore
@@ -91,16 +94,24 @@ public void setCurrent(final Account account) {
9194

9295

9396
public AccountDTO toDTO() {
94-
if (currentDTO == null && current != null) {
95-
currentDTO = current.toDTO();
96-
}
9797
return currentDTO;
9898
}
9999

100+
public Long getId() {
101+
return currentId;
102+
}
103+
100104
public Locale getAccountLocale() {
101105
if (accountLocale == null) {
102106
accountLocale = Locale.getDefault();
103107
}
104108
return accountLocale;
105109
}
110+
111+
private AccountService getService() {
112+
if (service == null) {
113+
service = Containers.get().findObject(AccountService.class);
114+
}
115+
return service;
116+
}
106117
}

sources/core/src/main/java/tools/dynamia/modules/saas/domain/Account.java

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
package tools.dynamia.modules.saas.domain;
1919

2020
import com.fasterxml.jackson.annotation.JsonIgnore;
21+
import jakarta.persistence.*;
22+
import jakarta.validation.constraints.Max;
23+
import jakarta.validation.constraints.Min;
24+
import jakarta.validation.constraints.NotNull;
25+
import jakarta.validation.constraints.Size;
2126
import org.hibernate.annotations.BatchSize;
2227
import org.hibernate.annotations.CacheConcurrencyStrategy;
2328
import tools.dynamia.commons.DateTimeUtils;
@@ -33,12 +38,7 @@
3338
import tools.dynamia.modules.saas.api.enums.AccountStatus;
3439
import tools.dynamia.web.util.HttpUtils;
3540

36-
import jakarta.persistence.*;
37-
import jakarta.validation.constraints.Max;
38-
import jakarta.validation.constraints.Min;
39-
import jakarta.validation.constraints.NotNull;
40-
import jakarta.validation.constraints.Size;
41-
41+
import java.io.Serial;
4242
import java.math.BigDecimal;
4343
import java.time.ZoneId;
4444
import java.util.ArrayList;
@@ -59,6 +59,7 @@ public class Account extends SimpleEntity implements Transferable<AccountDTO> {
5959
/**
6060
*
6161
*/
62+
@Serial
6263
private static final long serialVersionUID = 684169179001325225L;
6364

6465
@NotNull
@@ -93,14 +94,14 @@ public class Account extends SimpleEntity implements Transferable<AccountDTO> {
9394
private Date creationDate = new Date();
9495
private boolean defaultAccount;
9596
private String skin;
96-
@OneToOne
97+
@ManyToOne
9798
@JsonIgnore
9899
private EntityFile logo;
99100
@Column(length = 600)
100101
private String logoURL;
101102
private String locale;
102103
private String timeZone;
103-
@OneToOne
104+
@ManyToOne
104105
@JsonIgnore
105106
private AccountProfile profile;
106107
private long users;
@@ -138,6 +139,7 @@ public class Account extends SimpleEntity implements Transferable<AccountDTO> {
138139
private String globalMessage;
139140
private boolean showGlobalMessage;
140141
private String globalMessageType;
142+
@JsonIgnore
141143
@OneToMany(mappedBy = "account", cascade = CascadeType.ALL, orphanRemoval = true)
142144
private List<AccountFeature> features = new ArrayList<>();
143145
private BigDecimal balance = BigDecimal.ZERO;
@@ -146,6 +148,7 @@ public class Account extends SimpleEntity implements Transferable<AccountDTO> {
146148
@Temporal(TemporalType.DATE)
147149
private Date discountExpire;
148150
@OneToMany(mappedBy = "account", cascade = CascadeType.ALL, orphanRemoval = true)
151+
@JsonIgnore
149152
private List<AccountAdditionalService> additionalServices = new ArrayList<>();
150153
@Column(length = 2000)
151154
private String customerInfo;
@@ -158,12 +161,17 @@ public class Account extends SimpleEntity implements Transferable<AccountDTO> {
158161
private boolean useTempPaymentDay;
159162
private AccountStatus oldStatus;
160163

161-
@OneToOne
164+
@ManyToOne
162165
private AccountCategory category;
163166

164-
@OneToOne
167+
@ManyToOne
165168
private AccountReseller reseller;
166169

170+
@ManyToOne
171+
private AccountRegion accountRegion;
172+
private boolean templateAccount;
173+
174+
167175
private long openTicketsCount;
168176
private long closedTicketsCount;
169177
private boolean autoInit = true;
@@ -886,4 +894,20 @@ public String getRedirect() {
886894
public void setRedirect(String redirect) {
887895
this.redirect = redirect;
888896
}
897+
898+
public AccountRegion getAccountRegion() {
899+
return accountRegion;
900+
}
901+
902+
public void setAccountRegion(AccountRegion accountRegion) {
903+
this.accountRegion = accountRegion;
904+
}
905+
906+
public boolean isTemplateAccount() {
907+
return templateAccount;
908+
}
909+
910+
public void setTemplateAccount(boolean templateAccount) {
911+
this.templateAccount = templateAccount;
912+
}
889913
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
package tools.dynamia.modules.saas.domain;
2+
3+
import jakarta.persistence.Column;
4+
import jakarta.persistence.Entity;
5+
import jakarta.persistence.Table;
6+
import jakarta.validation.constraints.NotNull;
7+
import tools.dynamia.domain.jpa.SimpleEntity;
8+
9+
@Entity
10+
@Table(name = "saas_payments_providers")
11+
public class AccountPaymentProvider extends SimpleEntity {
12+
13+
@NotNull
14+
private String name;
15+
@Column(length = 500)
16+
private String apiKey;
17+
@Column(length = 500)
18+
private String apiSecret;
19+
private String serviceURL;
20+
private String merchantId;
21+
private boolean testMode;
22+
23+
private boolean active = true;
24+
25+
private String paymentProcessor;
26+
27+
public String getName() {
28+
return name;
29+
}
30+
31+
public void setName(String name) {
32+
this.name = name;
33+
}
34+
35+
public String getApiKey() {
36+
return apiKey;
37+
}
38+
39+
public void setApiKey(String apiKey) {
40+
this.apiKey = apiKey;
41+
}
42+
43+
public String getApiSecret() {
44+
return apiSecret;
45+
}
46+
47+
public void setApiSecret(String apiSecret) {
48+
this.apiSecret = apiSecret;
49+
}
50+
51+
public String getServiceURL() {
52+
return serviceURL;
53+
}
54+
55+
public void setServiceURL(String serviceURL) {
56+
this.serviceURL = serviceURL;
57+
}
58+
59+
public boolean isTestMode() {
60+
return testMode;
61+
}
62+
63+
public void setTestMode(boolean testMode) {
64+
this.testMode = testMode;
65+
}
66+
67+
public String getMerchantId() {
68+
return merchantId;
69+
}
70+
71+
public void setMerchantId(String merchantId) {
72+
this.merchantId = merchantId;
73+
}
74+
75+
public boolean isActive() {
76+
return active;
77+
}
78+
79+
public void setActive(boolean active) {
80+
this.active = active;
81+
}
82+
83+
@Override
84+
public String toString() {
85+
return name;
86+
}
87+
88+
public String getPaymentProcessor() {
89+
return paymentProcessor;
90+
}
91+
92+
public void setPaymentProcessor(String paymentProcessor) {
93+
this.paymentProcessor = paymentProcessor;
94+
}
95+
}

0 commit comments

Comments
 (0)