|
19 | 19 | import com.agiletec.aps.system.services.group.Group; |
20 | 20 | import com.agiletec.apsadmin.system.ApsAdminSystemConstants; |
21 | 21 | import com.agiletec.plugins.jacms.aps.system.services.content.model.Content; |
| 22 | +import java.util.Arrays; |
| 23 | +import org.apache.commons.lang.StringUtils; |
| 24 | +import org.entando.entando.aps.system.services.userpreferences.IUserPreferencesManager; |
| 25 | +import org.entando.entando.aps.system.services.userpreferences.UserPreferences; |
22 | 26 |
|
23 | 27 | /** |
24 | 28 | * Action gestore delle operazioni di creazione nuovo contenuto. |
@@ -69,13 +73,31 @@ public String createNewVoid() { |
69 | 73 | public String createNew() { |
70 | 74 | try { |
71 | 75 | _logger.debug("Create new content"); |
| 76 | + String username = getCurrentUser().getUsername(); |
72 | 77 | Content prototype = this.getContentManager().createContentType(this.getContentTypeCode()); |
73 | 78 | if (null == prototype) { |
74 | 79 | this.addFieldError("contentTypeCode", this.getText("error.content.type.invalid")); |
75 | 80 | _logger.debug("Invalid content type"); |
76 | 81 | return INPUT; |
77 | 82 | } |
78 | | - prototype.setFirstEditor(this.getCurrentUser().getUsername()); |
| 83 | + prototype.setFirstEditor(username); |
| 84 | + UserPreferences pref = this.getUserPreferencesManager().getUserPreferences(username); |
| 85 | + if (pref != null) { |
| 86 | + String defaultContentOwnerGroup = pref.getDefaultContentOwnerGroup(); |
| 87 | + String defaultContentJoinGroups = pref.getDefaultContentJoinGroups(); |
| 88 | + if (StringUtils.isNotBlank(defaultContentJoinGroups)) { |
| 89 | + String[] joinGroup = defaultContentJoinGroups.split(";"); |
| 90 | + Arrays.stream(joinGroup).filter(c -> null != this.getGroup(c)) |
| 91 | + .forEach(g -> { |
| 92 | + _logger.info("adding join group {} from user {} preferences", g, username); |
| 93 | + prototype.addGroup(g); |
| 94 | + }); |
| 95 | + } |
| 96 | + if (StringUtils.isNotBlank(defaultContentOwnerGroup) && null != this.getGroup(defaultContentOwnerGroup)) { |
| 97 | + prototype.setMainGroup(defaultContentOwnerGroup); |
| 98 | + _logger.info("setting ownerGroup to {}", defaultContentOwnerGroup); |
| 99 | + } |
| 100 | + } |
79 | 101 | this.fillSessionAttribute(prototype); |
80 | 102 | } catch (Throwable t) { |
81 | 103 | _logger.error("error in createNew", t); |
@@ -149,10 +171,19 @@ public String getContentStatus() { |
149 | 171 | public void setContentStatus(String contentStatus) { |
150 | 172 | this._contentStatus = contentStatus; |
151 | 173 | } |
| 174 | + |
| 175 | + public IUserPreferencesManager getUserPreferencesManager() { |
| 176 | + return userPreferencesManager; |
| 177 | + } |
| 178 | + public void setUserPreferencesManager(IUserPreferencesManager userPreferencesManager) { |
| 179 | + this.userPreferencesManager = userPreferencesManager; |
| 180 | + } |
152 | 181 |
|
153 | 182 | private String _contentTypeCode; |
154 | 183 | private String _contentDescription; |
155 | 184 | private String _contentMainGroup; |
156 | 185 | private String _contentStatus; |
| 186 | + |
| 187 | + private transient IUserPreferencesManager userPreferencesManager; |
157 | 188 |
|
158 | 189 | } |
0 commit comments