Search Widgets for publications and associated types
parent
14a7d00a73
commit
f10a3fda1e
|
|
@ -0,0 +1,82 @@
|
||||||
|
/*
|
||||||
|
* 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.contenttypes.ui;
|
||||||
|
|
||||||
|
import com.arsdigita.bebop.PageState;
|
||||||
|
import com.arsdigita.bebop.form.Widget;
|
||||||
|
import com.arsdigita.bebop.parameters.LongParameter;
|
||||||
|
import com.arsdigita.cms.CMS;
|
||||||
|
import com.arsdigita.xml.Element;
|
||||||
|
|
||||||
|
import org.libreccm.cdi.utils.CdiUtil;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
public class JournalSearchWidget extends Widget {
|
||||||
|
|
||||||
|
public JournalSearchWidget(final String name) {
|
||||||
|
super(new LongParameter(name));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCompound() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getType() {
|
||||||
|
return "journal-search-widget";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getElementTag() {
|
||||||
|
return "cms:journal-search-widget";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void generateWidget(
|
||||||
|
final PageState state, final Element parent
|
||||||
|
) {
|
||||||
|
final Element widget = parent.newChildElement(getElementTag(),
|
||||||
|
CMS.CMS_XML_NS);
|
||||||
|
|
||||||
|
widget.addAttribute("name", getName());
|
||||||
|
|
||||||
|
final Long value = (Long) getValue(state);
|
||||||
|
if (value != null) {
|
||||||
|
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
|
final JournalSearchWidgetController controller = cdiUtil
|
||||||
|
.findBean(JournalSearchWidgetController.class);
|
||||||
|
|
||||||
|
final Map<String, String> data = controller.getData(value);
|
||||||
|
|
||||||
|
final Element selected = widget
|
||||||
|
.newChildElement("cms:selected-journal", CMS.CMS_XML_NS);
|
||||||
|
selected.addAttribute(
|
||||||
|
"journalId",
|
||||||
|
data.get(JournalSearchWidgetController.JOURNAL_ID)
|
||||||
|
);
|
||||||
|
selected.addAttribute(
|
||||||
|
"title",
|
||||||
|
data.get(JournalSearchWidgetController.TITLE)
|
||||||
|
);
|
||||||
|
selected.addAttribute(
|
||||||
|
"symbol",
|
||||||
|
data.get(JournalSearchWidgetController.SYMBOL)
|
||||||
|
);
|
||||||
|
selected.addAttribute(
|
||||||
|
"issn",
|
||||||
|
data.get(JournalSearchWidgetController.ISSN));
|
||||||
|
|
||||||
|
exportAttributes(widget);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,58 @@
|
||||||
|
/*
|
||||||
|
* 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.contenttypes.ui;
|
||||||
|
|
||||||
|
import org.libreccm.l10n.GlobalizationHelper;
|
||||||
|
import org.scientificcms.publications.Journal;
|
||||||
|
import org.scientificcms.publications.JournalRepository;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.enterprise.context.RequestScoped;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.transaction.Transactional;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
@RequestScoped
|
||||||
|
public class JournalSearchWidgetController {
|
||||||
|
|
||||||
|
protected static final String JOURNAL_ID = "journalId";
|
||||||
|
|
||||||
|
protected static final String TITLE = "title";
|
||||||
|
|
||||||
|
protected static final String SYMBOL = "symbol";
|
||||||
|
|
||||||
|
protected static final String ISSN = "issn";
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private JournalRepository journalRepository;
|
||||||
|
|
||||||
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
|
public Map<String, String> getData(final long journalId) {
|
||||||
|
|
||||||
|
final Journal journal = journalRepository
|
||||||
|
.findById(journalId)
|
||||||
|
.orElseThrow(
|
||||||
|
() -> new IllegalArgumentException(
|
||||||
|
String.format("No Journal with ID %d found.", journalId)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
final Map<String, String> data = new HashMap<>();
|
||||||
|
|
||||||
|
data.put(JOURNAL_ID, Long.toString(journal.getJournalId()));
|
||||||
|
data.put(TITLE, journal.getTitle());
|
||||||
|
data.put(SYMBOL, journal.getSymbol());
|
||||||
|
data.put(ISSN, journal.getIssn());
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,109 @@
|
||||||
|
/*
|
||||||
|
* 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.contenttypes.ui;
|
||||||
|
|
||||||
|
import com.arsdigita.bebop.PageState;
|
||||||
|
import com.arsdigita.bebop.form.Widget;
|
||||||
|
import com.arsdigita.bebop.parameters.LongParameter;
|
||||||
|
import com.arsdigita.cms.CMS;
|
||||||
|
import com.arsdigita.xml.Element;
|
||||||
|
|
||||||
|
import org.libreccm.cdi.utils.CdiUtil;
|
||||||
|
import org.scientificcms.publications.Publication;
|
||||||
|
import org.scientificcms.publications.PublicationWithPublisher;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
public class PublicationSearchWidget extends Widget {
|
||||||
|
|
||||||
|
private Class<? extends Publication> type;
|
||||||
|
|
||||||
|
public PublicationSearchWidget(final String name) {
|
||||||
|
super(new LongParameter(name));
|
||||||
|
}
|
||||||
|
|
||||||
|
public PublicationSearchWidget(
|
||||||
|
final String name, final Class<? extends Publication> type
|
||||||
|
) {
|
||||||
|
this(name);
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCompound() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getType() {
|
||||||
|
return "publication-search-widget";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getElementTag() {
|
||||||
|
return "cms:publication-search-widget";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void generateWidget(final PageState state,
|
||||||
|
final Element parent) {
|
||||||
|
final Element widget = parent.newChildElement(
|
||||||
|
getElementTag(), CMS.CMS_XML_NS
|
||||||
|
);
|
||||||
|
|
||||||
|
widget.addAttribute("name", getName());
|
||||||
|
|
||||||
|
if (type != null) {
|
||||||
|
widget.addAttribute("publication-type", type.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
final Long value = (Long) getValue(state);
|
||||||
|
if (value != null) {
|
||||||
|
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
|
final PublicationSearchWidgetController controller = cdiUtil
|
||||||
|
.findBean(PublicationSearchWidgetController.class);
|
||||||
|
|
||||||
|
final Map<String, String> data = controller.getData(value);
|
||||||
|
|
||||||
|
final Element selected = widget.newChildElement(
|
||||||
|
"cms:selected-publication", CMS.CMS_XML_NS
|
||||||
|
);
|
||||||
|
selected.addAttribute(
|
||||||
|
"publicationId",
|
||||||
|
data.get(PublicationSearchWidgetController.PUBLICATION_ID)
|
||||||
|
);
|
||||||
|
|
||||||
|
selected.addAttribute(
|
||||||
|
"title",
|
||||||
|
data.get(PublicationSearchWidgetController.TITLE)
|
||||||
|
);
|
||||||
|
|
||||||
|
selected.addAttribute(
|
||||||
|
"year",
|
||||||
|
data.get(PublicationSearchWidgetController.YEAR)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (type != null
|
||||||
|
&& PublicationWithPublisher.class.isAssignableFrom(type)) {
|
||||||
|
selected.addAttribute(
|
||||||
|
"publisher",
|
||||||
|
data.get(PublicationSearchWidgetController.PUBLISHER)
|
||||||
|
);
|
||||||
|
selected.addAttribute(
|
||||||
|
"place",
|
||||||
|
data.get(PublicationSearchWidgetController.PLACE)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
exportAttributes(widget);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,95 @@
|
||||||
|
/*
|
||||||
|
* 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.contenttypes.ui;
|
||||||
|
|
||||||
|
import org.libreccm.l10n.GlobalizationHelper;
|
||||||
|
import org.librecms.assets.Person;
|
||||||
|
import org.scientificcms.publications.Authorship;
|
||||||
|
import org.scientificcms.publications.Publication;
|
||||||
|
import org.scientificcms.publications.PublicationRepository;
|
||||||
|
import org.scientificcms.publications.PublicationWithPublisher;
|
||||||
|
import org.scientificcms.publications.Publisher;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import javax.enterprise.context.RequestScoped;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.transaction.Transactional;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
@RequestScoped
|
||||||
|
public class PublicationSearchWidgetController {
|
||||||
|
|
||||||
|
protected static final String PUBLICATION_ID = "publicationId";
|
||||||
|
|
||||||
|
protected static final String TITLE = "title";
|
||||||
|
|
||||||
|
protected static final String YEAR = "year";
|
||||||
|
|
||||||
|
protected static final String AUTHORS = "authors";
|
||||||
|
|
||||||
|
protected static final String PUBLISHER = "publisher";
|
||||||
|
|
||||||
|
protected static final String PLACE = "place";
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private PublicationRepository publicationRepository;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private GlobalizationHelper globalizationHelper;
|
||||||
|
|
||||||
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
|
public Map<String, String> getData(final long publicationId) {
|
||||||
|
|
||||||
|
final Publication publication = publicationRepository
|
||||||
|
.findById(publicationId)
|
||||||
|
.orElseThrow(
|
||||||
|
() -> new IllegalArgumentException(
|
||||||
|
String.format("No Publication with ID %d found.",
|
||||||
|
publicationId)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
final Map<String, String> data = new HashMap<>();
|
||||||
|
|
||||||
|
data.put(PUBLICATION_ID, Long.toString(publication.getPublicationId()));
|
||||||
|
data.put(
|
||||||
|
TITLE,
|
||||||
|
globalizationHelper.getValueFromLocalizedString(
|
||||||
|
publication.getTitle()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
data.put(YEAR, Integer.toString(publication.getYearOfPublication()));
|
||||||
|
data.put(
|
||||||
|
AUTHORS,
|
||||||
|
publication
|
||||||
|
.getAuthorships()
|
||||||
|
.stream()
|
||||||
|
.sorted()
|
||||||
|
.map(Authorship::getAuthor)
|
||||||
|
.map(Person::getPersonName)
|
||||||
|
.map(name -> String.format("%s, %s",
|
||||||
|
name.getSurname(),
|
||||||
|
name.getGivenName()))
|
||||||
|
.collect(Collectors.joining("; "))
|
||||||
|
);
|
||||||
|
|
||||||
|
if (publication instanceof PublicationWithPublisher) {
|
||||||
|
final Publisher publisher = ((PublicationWithPublisher) publication)
|
||||||
|
.getPublisher();
|
||||||
|
data.put(PUBLISHER, publisher.getName());
|
||||||
|
data.put(PLACE, publisher.getPlace());
|
||||||
|
}
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,79 @@
|
||||||
|
/*
|
||||||
|
* 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.contenttypes.ui;
|
||||||
|
|
||||||
|
import com.arsdigita.bebop.PageState;
|
||||||
|
import com.arsdigita.bebop.form.Widget;
|
||||||
|
import com.arsdigita.bebop.parameters.LongParameter;
|
||||||
|
import com.arsdigita.cms.CMS;
|
||||||
|
import com.arsdigita.xml.Element;
|
||||||
|
|
||||||
|
import org.libreccm.cdi.utils.CdiUtil;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
public class PublisherSearchWidget extends Widget {
|
||||||
|
|
||||||
|
public PublisherSearchWidget(final String name) {
|
||||||
|
super(new LongParameter(name));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCompound() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getType() {
|
||||||
|
return "publisher-search-widget";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getElementTag() {
|
||||||
|
return "cms:publisher-search-widget";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void generateWidget(
|
||||||
|
final PageState state, final Element parent
|
||||||
|
) {
|
||||||
|
final Element widget = parent.newChildElement(getElementTag(),
|
||||||
|
CMS.CMS_XML_NS);
|
||||||
|
|
||||||
|
widget.addAttribute("name", getName());
|
||||||
|
|
||||||
|
final Long value = (Long) getValue(state);
|
||||||
|
if (value != null) {
|
||||||
|
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
|
final PublisherSearchWidgetController controller = cdiUtil
|
||||||
|
.findBean(PublisherSearchWidgetController.class);
|
||||||
|
|
||||||
|
final Map<String, String> data = controller.getData(value);
|
||||||
|
|
||||||
|
final Element selected = widget
|
||||||
|
.newChildElement("cms:selected-publisher", CMS.CMS_XML_NS);
|
||||||
|
selected.addAttribute(
|
||||||
|
"publisherId",
|
||||||
|
data.get(PublisherSearchWidgetController.PUBLISHER_ID)
|
||||||
|
);
|
||||||
|
selected.addAttribute(
|
||||||
|
"name",
|
||||||
|
data.get(PublisherSearchWidgetController.NAME)
|
||||||
|
);
|
||||||
|
selected.addAttribute(
|
||||||
|
"place",
|
||||||
|
data.get(PublisherSearchWidgetController.PLACE)
|
||||||
|
);
|
||||||
|
|
||||||
|
exportAttributes(widget);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,51 @@
|
||||||
|
/*
|
||||||
|
* 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.contenttypes.ui;
|
||||||
|
|
||||||
|
import org.scientificcms.publications.Publisher;
|
||||||
|
import org.scientificcms.publications.PublisherRepository;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.enterprise.context.RequestScoped;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.transaction.Transactional;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
@RequestScoped
|
||||||
|
public class PublisherSearchWidgetController {
|
||||||
|
|
||||||
|
protected static final String PUBLISHER_ID = "publisherId";
|
||||||
|
protected static final String NAME = "name";
|
||||||
|
protected static final String PLACE = "place";
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private PublisherRepository publisherRepository;
|
||||||
|
|
||||||
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
|
public Map<String, String> getData(final long publisherId) {
|
||||||
|
|
||||||
|
final Publisher publisher = publisherRepository
|
||||||
|
.findById(publisherId)
|
||||||
|
.orElseThrow(
|
||||||
|
() -> new IllegalArgumentException(
|
||||||
|
String.format("No Publisher with ID %d found.", publisherId)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
final Map<String, String> data = new HashMap<>();
|
||||||
|
|
||||||
|
data.put(PUBLISHER_ID, Long.toString(publisher.getPublisherId()));
|
||||||
|
data.put(NAME, publisher.getName());
|
||||||
|
data.put(PLACE, publisher.getPlace());
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,75 @@
|
||||||
|
/*
|
||||||
|
* 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.contenttypes.ui;
|
||||||
|
|
||||||
|
import com.arsdigita.bebop.PageState;
|
||||||
|
import com.arsdigita.bebop.form.Widget;
|
||||||
|
import com.arsdigita.bebop.parameters.LongParameter;
|
||||||
|
import com.arsdigita.cms.CMS;
|
||||||
|
import com.arsdigita.xml.Element;
|
||||||
|
|
||||||
|
import org.libreccm.cdi.utils.CdiUtil;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
public class SeriesSearchWidget extends Widget {
|
||||||
|
|
||||||
|
public SeriesSearchWidget(final String name) {
|
||||||
|
super(new LongParameter(name));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCompound() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getType() {
|
||||||
|
return "series-search-widget";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getElementTag() {
|
||||||
|
return "cms:series-search-widget";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void generateWidget(
|
||||||
|
final PageState state, final Element parent
|
||||||
|
) {
|
||||||
|
final Element widget = parent.newChildElement(getElementTag(),
|
||||||
|
CMS.CMS_XML_NS);
|
||||||
|
|
||||||
|
widget.addAttribute("name", getName());
|
||||||
|
|
||||||
|
final Long value = (Long) getValue(state);
|
||||||
|
if (value != null) {
|
||||||
|
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
|
final SeriesSearchWidgetController controller = cdiUtil
|
||||||
|
.findBean(SeriesSearchWidgetController.class);
|
||||||
|
|
||||||
|
final Map<String, String> data = controller.getData(value);
|
||||||
|
|
||||||
|
final Element selected = widget
|
||||||
|
.newChildElement("cms:selected-series", CMS.CMS_XML_NS);
|
||||||
|
selected.addAttribute(
|
||||||
|
"series",
|
||||||
|
data.get(SeriesSearchWidgetController.SERIES_ID)
|
||||||
|
);
|
||||||
|
selected.addAttribute(
|
||||||
|
"title",
|
||||||
|
data.get(SeriesSearchWidgetController.TITLE)
|
||||||
|
);
|
||||||
|
|
||||||
|
exportAttributes(widget);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,58 @@
|
||||||
|
/*
|
||||||
|
* 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.contenttypes.ui;
|
||||||
|
|
||||||
|
import org.libreccm.l10n.GlobalizationHelper;
|
||||||
|
import org.scientificcms.publications.Series;
|
||||||
|
import org.scientificcms.publications.SeriesRepository;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.enterprise.context.RequestScoped;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.transaction.Transactional;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
@RequestScoped
|
||||||
|
public class SeriesSearchWidgetController {
|
||||||
|
|
||||||
|
protected static final String SERIES_ID = "seriesId";
|
||||||
|
|
||||||
|
protected static final String TITLE = "title";
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private SeriesRepository seriesRepository;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private GlobalizationHelper globalizationHelper;
|
||||||
|
|
||||||
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
|
public Map<String, String> getData(final long seriesId) {
|
||||||
|
|
||||||
|
final Series series = seriesRepository
|
||||||
|
.findById(seriesId)
|
||||||
|
.orElseThrow(
|
||||||
|
() -> new IllegalArgumentException(
|
||||||
|
String.format("No Series with ID %d found.", seriesId)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
final Map<String, String> data = new HashMap<>();
|
||||||
|
|
||||||
|
data.put(SERIES_ID, Long.toString(series.getSeriesId()));
|
||||||
|
data.put(
|
||||||
|
TITLE,
|
||||||
|
globalizationHelper.getValueFromLocalizedString(series.getTitle())
|
||||||
|
);
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue