Skip to content

Commit 08aa3be

Browse files
SilverYoChammoqui
authored andcommitted
Features about QuickInfo component:
* #13827, adding copy/paste a news functionality to quick info component. * #13828, handling keywords at news level.
1 parent b1e7f4f commit 08aa3be

File tree

15 files changed

+395
-26
lines changed

15 files changed

+395
-26
lines changed

quickinfo/quickinfo-configuration/src/main/config/properties/org/silverpeas/quickinfo/multilang/quickinfo.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ quickinfo.news.broadcast.mode = Diffusion
3838
quickinfo.news.broadcast.mode.major = Importante
3939
quickinfo.news.broadcast.mode.ticker = D\u00e9filante
4040
quickinfo.news.broadcast.mode.blocking = Bloquante
41+
quickinfo.news.keywords = Mots cl\u00e9s
4142

4243
quickinfo.news.untitled = Nouvelle actualit\u00e9
4344
quickinfo.news.draft.info = Cette actualit\u00e9 est actuellement un brouillon... <a href="#" onclick="javascript:publish()">Publiez-la maintenant !?</a>

quickinfo/quickinfo-configuration/src/main/config/properties/org/silverpeas/quickinfo/multilang/quickinfo_de.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ quickinfo.news.broadcast.mode = Broadcast
3838
quickinfo.news.broadcast.mode.major = Important
3939
quickinfo.news.broadcast.mode.ticker = Ticker
4040
quickinfo.news.broadcast.mode.blocking = Blocking
41+
quickinfo.news.keywords=Schl\u00fcsselworte
4142

4243
quickinfo.news.untitled = Untitled news
4344
quickinfo.news.draft.info = This news is a draft... <a href="#" onclick="javascript:publish()">Publish it now !?</a>

quickinfo/quickinfo-configuration/src/main/config/properties/org/silverpeas/quickinfo/multilang/quickinfo_en.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ quickinfo.news.broadcast.mode = Broadcast
3838
quickinfo.news.broadcast.mode.major = Important
3939
quickinfo.news.broadcast.mode.ticker = Ticker
4040
quickinfo.news.broadcast.mode.blocking = Blocking
41+
quickinfo.news.keywords=Keywords
4142

4243
quickinfo.news.untitled = Untitled news
4344
quickinfo.news.draft.info = This news is a draft... <a href="#" onclick="javascript:publish()">Publish it now !?</a>

quickinfo/quickinfo-configuration/src/main/config/properties/org/silverpeas/quickinfo/multilang/quickinfo_fr.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ quickinfo.news.broadcast.mode = Diffusion
3838
quickinfo.news.broadcast.mode.major = Importante
3939
quickinfo.news.broadcast.mode.ticker = D\u00e9filante
4040
quickinfo.news.broadcast.mode.blocking = Bloquante
41+
quickinfo.news.keywords = Mots cl\u00e9s
4142

4243
quickinfo.news.untitled = Nouvelle actualit\u00e9
4344
quickinfo.news.draft.info = Cette actualit\u00e9 est actuellement un brouillon... <a href="#" onclick="javascript:publish()">Publiez-la maintenant !?</a>

quickinfo/quickinfo-library/src/integration-test/java/org/silverpeas/components/quickinfo/repository/NewsRepositoryIT.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,13 @@ public void testSaving() {
8787
OperationContext.fromUser(user);
8888
News savedNews = Transaction.performInOne(() -> {
8989
Period visibility = Period.between(LocalDate.now(), LocalDate.now().plusMonths(1));
90-
News news =
91-
new News("test", "test", visibility, true, true, false);
90+
News news = News.builder()
91+
.setTitleAndDescription("test", "test")
92+
.setVisibilityPeriod(visibility)
93+
.setImportant(true)
94+
.setTicker(true)
95+
.setMandatory(false)
96+
.build();
9297
news.setComponentInstanceId("quickinfo1");
9398
news.setPublicationId("45789");
9499
news.createdBy(user);

quickinfo/quickinfo-library/src/main/java/org/silverpeas/components/quickinfo/model/DefaultQuickInfoService.java

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,13 @@
3535
import org.silverpeas.components.quickinfo.service.QuickInfoContentManager;
3636
import org.silverpeas.components.quickinfo.service.QuickInfoDateComparatorDesc;
3737
import org.silverpeas.core.ResourceReference;
38+
import org.silverpeas.core.admin.component.model.PasteDetail;
3839
import org.silverpeas.core.admin.service.OrganizationController;
3940
import org.silverpeas.core.admin.service.OrganizationControllerProvider;
4041
import org.silverpeas.core.annotation.Service;
4142
import org.silverpeas.core.contribution.attachment.AttachmentServiceProvider;
4243
import org.silverpeas.core.contribution.attachment.model.Attachments;
44+
import org.silverpeas.core.contribution.attachment.model.DocumentType;
4345
import org.silverpeas.core.contribution.attachment.model.SimpleDocumentPK;
4446
import org.silverpeas.core.contribution.content.wysiwyg.service.WysiwygController;
4547
import org.silverpeas.core.contribution.contentcontainer.content.ContentManagerException;
@@ -49,6 +51,7 @@
4951
import org.silverpeas.core.contribution.publication.service.PublicationService;
5052
import org.silverpeas.core.i18n.I18NHelper;
5153
import org.silverpeas.core.index.indexing.model.IndexManager;
54+
import org.silverpeas.core.io.media.image.thumbnail.control.ThumbnailController;
5255
import org.silverpeas.core.io.upload.UploadedFile;
5356
import org.silverpeas.core.notification.system.ResourceEvent;
5457
import org.silverpeas.core.notification.user.client.constant.NotifAction;
@@ -89,6 +92,7 @@
8992
import static java.util.Collections.singletonList;
9093
import static java.util.function.Predicate.not;
9194
import static org.silverpeas.components.quickinfo.notification.QuickInfoDelayedVisibilityUserNotificationReminder.QUICKINFO_DELAYED_VISIBILITY_USER_NOTIFICATION;
95+
import static org.silverpeas.core.contribution.attachment.AttachmentServiceProvider.getAttachmentService;
9296
import static org.silverpeas.core.pdc.pdc.model.PdcClassification.aPdcClassificationOfContent;
9397

9498
@Service
@@ -175,7 +179,7 @@ public boolean isRelatedTo(final String instanceId) {
175179
@Override
176180
@Transactional
177181
public News create(final News news) {
178-
ResourceReference volatileAttachmentSourcePK =
182+
ResourceReference volatileAttachmentSourceRef =
179183
new ResourceReference(news.getPublicationId(), news.getComponentInstanceId());
180184

181185
// Creating publication
@@ -192,12 +196,12 @@ public News create(final News news) {
192196

193197
// Attaching all documents linked to volatile news to the persisted news
194198
List<SimpleDocumentPK> movedDocumentPks = AttachmentServiceProvider.getAttachmentService()
195-
.moveAllDocuments(volatileAttachmentSourcePK,
199+
.moveAllDocuments(volatileAttachmentSourceRef,
196200
savedNews.getPublication().getPK().toResourceReference());
197201
if (!movedDocumentPks.isEmpty()) {
198202
// Change images path in wysiwyg
199203
WysiwygController.wysiwygPlaceHaveChanged(news.getComponentInstanceId(),
200-
volatileAttachmentSourcePK.getId(), news.getComponentInstanceId(), savedNews.getId());
204+
volatileAttachmentSourceRef.getId(), news.getComponentInstanceId(), savedNews.getId());
201205
}
202206

203207
// Referring new content into taxonomy
@@ -213,6 +217,60 @@ public News create(final News news) {
213217
return savedNews;
214218
}
215219

220+
@Override
221+
@Transactional
222+
public News copyNews(final News newsToCopy, final PasteDetail pasteDetail) {
223+
224+
// Initializing the news instance
225+
final News news = News.builder(newsToCopy).build();
226+
news.setDraft();
227+
news.setComponentInstanceId(pasteDetail.getToComponentId());
228+
news.setCreatorId(pasteDetail.getUserId());
229+
230+
// Creating linked publication
231+
PublicationDetail publication = news.getPublication();
232+
publication.setIndexOperation(IndexManager.NONE);
233+
final PublicationPK pubPK = getPublicationService().createPublication(publication);
234+
publication = getPublicationService().getDetail(pubPK);
235+
236+
// Saving the new news instance into repository
237+
news.setPublicationId(pubPK.getId());
238+
news.setPublication(publication);
239+
final News savedNews = newsRepository.save(news);
240+
241+
// Copying decorators
242+
final ResourceReference pubSourceRef = newsToCopy.getPublication().getPK().toReference();
243+
final ResourceReference pubDestRef = news.getPublication().getPK().toReference();
244+
// - PDC
245+
copyPdcPositions(newsToCopy, savedNews);
246+
// - attachment files
247+
getAttachmentService()
248+
.listDocumentsByForeignKeyAndType(pubSourceRef, DocumentType.attachment, null)
249+
.forEach(a -> getAttachmentService().copyDocument(a, pubDestRef));
250+
// - WYSIWYG content
251+
WysiwygController.copy(pubSourceRef.getComponentInstanceId(), pubSourceRef.getLocalId(),
252+
pubDestRef.getComponentInstanceId(), pubDestRef.getLocalId(), pasteDetail.getUserId());
253+
// - thumbnail
254+
ThumbnailController.copyThumbnail(pubSourceRef, pubDestRef);
255+
256+
return savedNews;
257+
}
258+
259+
private void copyPdcPositions(final News sourceNews, final News destNews) {
260+
String sourceCmpId = sourceNews.getComponentInstanceId();
261+
String destCmpId = destNews.getComponentInstanceId();
262+
int sourceId = quickInfoContentManager.getOrCreateSilverContentId(sourceNews.getPublication());
263+
int destId = quickInfoContentManager.getOrCreateSilverContentId(destNews.getPublication());
264+
try {
265+
pdcManager.copyPositions(sourceId, sourceCmpId, destId, destCmpId);
266+
} catch (PdcException e) {
267+
SilverLogger.getLogger(this).error(
268+
"can not copy pdc positions from publication {0} of news {1} to publication {2} of news {3}",
269+
new Object[]{sourceNews.getPublication().getPK(), sourceNews.getPK(),
270+
destNews.getPublication().getPK(), destNews.getPK()}, e);
271+
}
272+
}
273+
216274
@Override
217275
@Transactional
218276
public void publish(String id, String userId) {

quickinfo/quickinfo-library/src/main/java/org/silverpeas/components/quickinfo/model/News.java

Lines changed: 115 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -122,19 +122,32 @@ public class News extends SilverpeasJpaEntity<News, UuidIdentifier> implements S
122122
@Column
123123
private String publishedBy;
124124

125-
protected News() {
126-
// default constructor for the persistence engine
125+
/**
126+
* Gets a builder of {@link News} instances.
127+
* @return a {@link Builder} instance
128+
*/
129+
public static Builder builder() {
130+
return new Builder();
127131
}
128132

129-
public News(String name, String description, Period visibilityPeriod, boolean important,
130-
boolean ticker, boolean mandatory) {
131-
this.publication = PublicationDetail.builder()
132-
.setNameAndDescription(name, description)
133-
.build();
134-
this.publication.setVisibilityPeriod(visibilityPeriod);
135-
setImportant(important);
136-
setTicker(ticker);
137-
setMandatory(mandatory);
133+
/**
134+
* Gets a builder of {@link News} instances from data of another one.
135+
* @param news the news data to initialize with.
136+
* @return a {@link Builder} instance
137+
*/
138+
public static Builder builder(final News news) {
139+
return builder()
140+
.setTitleAndDescription(news.getTitle(), news.getDescription())
141+
.setKeywords(news.getKeywords())
142+
.setVisibilityPeriod(news.getVisibility().getPeriod())
143+
.setImportant(news.isImportant())
144+
.setTicker(news.isTicker())
145+
.setMandatory(news.isMandatory());
146+
}
147+
148+
protected News() {
149+
// default constructor for the persistence engine
150+
super();
138151
}
139152

140153
public NewsPK getPK() {
@@ -168,6 +181,14 @@ public String getDescription() {
168181
return getPublication().getDescription();
169182
}
170183

184+
public void setKeywords(String keywords) {
185+
getPublication().setKeywords(keywords);
186+
}
187+
188+
public String getKeywords() {
189+
return getPublication().getKeywords();
190+
}
191+
171192
public void setDescription(String desc) {
172193
getPublication().setDescription(desc);
173194
}
@@ -435,4 +456,87 @@ public boolean equals(final Object obj) {
435456
public ContributionModel getModel() {
436457
return new NewsModel(this);
437458
}
459+
460+
/**
461+
* A builder of a {@link News} instance by setting some of its properties.
462+
*/
463+
public static class Builder {
464+
465+
private final News news = new News();
466+
467+
public Builder() {
468+
news.publication = PublicationDetail.builder().build();
469+
}
470+
471+
/**
472+
* Builds a {@link News} instance from the properties that were previously set with this
473+
* builder.
474+
* @return a {@link News} instance.
475+
*/
476+
public News build() {
477+
return news;
478+
}
479+
480+
/**
481+
* Sets mandatory flag of the {@link News} instance to build.
482+
* @param mandatory the mandatory flag.
483+
* @return itself.
484+
*/
485+
public Builder setMandatory(boolean mandatory) {
486+
news.setMandatory(mandatory);
487+
return this;
488+
}
489+
490+
/**
491+
* Sets ticker flag of the {@link News} instance to build.
492+
* @param ticker the ticker flag.
493+
* @return itself.
494+
*/
495+
public Builder setTicker(boolean ticker) {
496+
news.setTicker(ticker);
497+
return this;
498+
}
499+
500+
/**
501+
* Sets important flag of the {@link News} instance to build.
502+
* @param important the important flag.
503+
* @return itself.
504+
*/
505+
public Builder setImportant(boolean important) {
506+
news.setImportant(important);
507+
return this;
508+
}
509+
510+
/**
511+
* Sets the visibility period of the {@link News} instance to build.
512+
* @param period the visibility period.
513+
* @return itself.
514+
*/
515+
public Builder setVisibilityPeriod(Period period) {
516+
news.setVisibilityPeriod(period);
517+
return this;
518+
}
519+
520+
/**
521+
* Sets the keywords of the {@link News} instance to build.
522+
* @param keywords the keywords of the news.
523+
* @return itself.
524+
*/
525+
public Builder setKeywords(final String keywords) {
526+
news.setKeywords(keywords);
527+
return this;
528+
}
529+
530+
/**
531+
* Sets the given title and description of the news to build.
532+
* @param title the title of the news.
533+
* @param description the description of the news.
534+
* @return itself.
535+
*/
536+
public Builder setTitleAndDescription(final String title, final String description) {
537+
news.setTitle(title);
538+
news.setDescription(description);
539+
return this;
540+
}
541+
}
438542
}

0 commit comments

Comments
 (0)