parent
b146cd833c
commit
efe1d9554e
|
|
@ -18,8 +18,11 @@
|
|||
*/
|
||||
package com.arsdigita.cms.ui.authoring.news;
|
||||
|
||||
import org.libreccm.l10n.GlobalizationHelper;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.librecms.contentsection.ContentSection;
|
||||
import org.librecms.contentsection.ContentSectionRepository;
|
||||
|
||||
|
|
@ -32,13 +35,18 @@ import javax.inject.Inject;
|
|||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.TypedQuery;
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
import org.libreccm.security.PermissionChecker;
|
||||
import org.libreccm.security.Role;
|
||||
import org.libreccm.security.RoleRepository;
|
||||
import org.libreccm.security.Shiro;
|
||||
import org.libreccm.security.User;
|
||||
import org.librecms.contentsection.ContentItemRepository;
|
||||
import org.librecms.contentsection.ContentType;
|
||||
import org.librecms.contentsection.ContentTypeRepository;
|
||||
import org.librecms.contenttypes.News;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Controller class for the {@link NewItemForm}.
|
||||
|
|
@ -111,4 +119,6 @@ class NewItemFormController {
|
|||
return query.getResultList();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,108 @@
|
|||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package com.arsdigita.cms.ui.authoring.news;
|
||||
|
||||
import org.librecms.contentsection.ContentItemRepository;
|
||||
import org.librecms.contenttypes.News;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
public class NewsController {
|
||||
|
||||
@Inject
|
||||
private ContentItemRepository itemRepo;
|
||||
|
||||
@Transactional
|
||||
protected String getDescription(
|
||||
final News fromNews, final Locale forLocale
|
||||
) {
|
||||
Objects.requireNonNull(fromNews);
|
||||
final News news = itemRepo
|
||||
.findById(fromNews.getObjectId(), News.class)
|
||||
.orElseThrow(
|
||||
() -> new IllegalArgumentException(
|
||||
String.format(
|
||||
"No News with ID %d available.", fromNews.getObjectId()
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
return news.getDescription().getValue(forLocale);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
protected String getText(final News fromNews, final Locale forLocale) {
|
||||
Objects.requireNonNull(fromNews);
|
||||
final News news = itemRepo
|
||||
.findById(fromNews.getObjectId(), News.class)
|
||||
.orElseThrow(
|
||||
() -> new IllegalArgumentException(
|
||||
String.format(
|
||||
"No News with ID %d available",
|
||||
fromNews.getObjectId()
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
return news.getText().getValue(forLocale);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
protected void updateText(
|
||||
final News ofNews,
|
||||
final Locale forLocale,
|
||||
final String text
|
||||
) {
|
||||
Objects.requireNonNull(ofNews);
|
||||
final News news = itemRepo
|
||||
.findById(ofNews.getObjectId(), News.class)
|
||||
.orElseThrow(
|
||||
() -> new IllegalArgumentException(
|
||||
String.format(
|
||||
"No News with ID %d available",
|
||||
ofNews.getObjectId()
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
news.getText().addValue(forLocale, text);
|
||||
itemRepo.save(news);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
protected void update(
|
||||
final News news,
|
||||
final Date releaseDate,
|
||||
final Locale locale,
|
||||
final String description
|
||||
) {
|
||||
Objects.requireNonNull(news);
|
||||
final News update = itemRepo
|
||||
.findById(news.getObjectId(), News.class)
|
||||
.orElseThrow(
|
||||
() -> new IllegalArgumentException(
|
||||
String.format(
|
||||
"No News with ID %d available",
|
||||
news.getObjectId()
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
update.setReleaseDate(releaseDate);
|
||||
update.getDescription().addValue(locale, description);
|
||||
itemRepo.save(update);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -36,7 +36,6 @@ import org.librecms.contenttypes.News;
|
|||
import com.arsdigita.cms.ui.authoring.BasicPageForm;
|
||||
import com.arsdigita.cms.ui.authoring.SelectedLanguageUtil;
|
||||
import com.arsdigita.globalization.GlobalizedMessage;
|
||||
import com.arsdigita.kernel.KernelConfig;
|
||||
|
||||
import org.libreccm.cdi.utils.CdiUtil;
|
||||
import org.libreccm.configuration.ConfigurationManager;
|
||||
|
|
@ -45,6 +44,7 @@ import org.librecms.contentsection.ContentItemRepository;
|
|||
import org.librecms.contenttypes.NewsConfig;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
|
|
@ -181,7 +181,10 @@ public class NewsPropertyForm extends BasicPageForm
|
|||
|
||||
releaseDateSelector.addYear(releaseDate);
|
||||
data.put(NEWS_DATE, releaseDate);
|
||||
data.put(LEAD, item.getDescription().getValue(selectedLocale));
|
||||
final NewsController controller = CdiUtil
|
||||
.createCdiUtil()
|
||||
.findBean(NewsController.class);
|
||||
data.put(LEAD, controller.getDescription(item, selectedLocale));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -218,21 +221,15 @@ public class NewsPropertyForm extends BasicPageForm
|
|||
.getSaveButton()
|
||||
.isSelected(event.getPageState())) {
|
||||
|
||||
final NewsController controller = CdiUtil
|
||||
.createCdiUtil()
|
||||
.findBean(NewsController.class);
|
||||
|
||||
final Date releaseDate = (java.util.Date) data.get(NEWS_DATE);
|
||||
final String description = (String) data.get(LEAD);
|
||||
final Locale selectedLocale = SelectedLanguageUtil
|
||||
.selectedLocale(state, selectedLanguageParam);
|
||||
|
||||
item.setReleaseDate((java.util.Date) data.get(NEWS_DATE));
|
||||
item
|
||||
.getDescription()
|
||||
.addValue(
|
||||
selectedLocale,
|
||||
(String) data.get(LEAD));
|
||||
|
||||
final ContentItemRepository itemRepo = CdiUtil
|
||||
.createCdiUtil()
|
||||
.findBean(ContentItemRepository.class);
|
||||
|
||||
itemRepo.save(item);
|
||||
controller.update(item, releaseDate, selectedLocale, description);
|
||||
}
|
||||
if (propertiesStep != null) {
|
||||
propertiesStep.maybeForwardToNextStep(event.getPageState());
|
||||
|
|
|
|||
|
|
@ -83,10 +83,13 @@ public class NewsTextBody extends TextBody {
|
|||
|
||||
final News news = getSelectedNews(state);
|
||||
|
||||
return news
|
||||
.getText()
|
||||
.getValue(SelectedLanguageUtil
|
||||
.selectedLocale(state, selectedLanguageParam));
|
||||
final NewsController controller = CdiUtil
|
||||
.createCdiUtil()
|
||||
.findBean(NewsController.class);
|
||||
return controller.getText(
|
||||
news,
|
||||
SelectedLanguageUtil.selectedLocale(state, selectedLanguageParam)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -97,11 +100,10 @@ public class NewsTextBody extends TextBody {
|
|||
final Locale selectedLocale = SelectedLanguageUtil
|
||||
.selectedLocale(state, selectedLanguageParam);
|
||||
|
||||
news.getText().addValue(selectedLocale, text);
|
||||
final ContentItemRepository itemRepo = CdiUtil
|
||||
final NewsController controller = CdiUtil
|
||||
.createCdiUtil()
|
||||
.findBean(ContentItemRepository.class);
|
||||
itemRepo.save(news);
|
||||
.findBean(NewsController.class);
|
||||
controller.updateText(news, selectedLocale, text);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue