Commit df6d2aa0 authored by Marco Descher's avatar Marco Descher 🏔

[16258] StickerService allow adding detail data to an attached sticker

parent 2bd0f7fb
Pipeline #12120 passed with stages
in 4 minutes and 46 seconds
......@@ -32,6 +32,9 @@ public class StickerObjectLink implements EntityWithId {
@Column(length = 25, nullable = false)
private String etikette;
@Column(length = 256, nullable = true)
private String data;
public String getObj(){
return obj;
}
......@@ -47,6 +50,14 @@ public class StickerObjectLink implements EntityWithId {
public void setEtikette(String stickerId){
this.etikette = stickerId;
}
public String getData(){
return data;
}
public void setData(String data){
this.data = data;
}
@Override
public int hashCode() {
......
......@@ -1876,4 +1876,18 @@ DROP TABLE TEMP_ETIKETTEN_OBJCLASS_LINK;
<where>param='dbversion'</where>
</update>
</changeSet>
<changeSet author="marco"
id="manual_table_ETIKETTEN_OBJECT_LINK_ADD_DATA">
<preConditions onFail="MARK_RAN">
<not>
<columnExists tableName="ETIKETTEN_OBJECT_LINK"
columnName="DATA" />
</not>
</preConditions>
<addColumn tableName="ETIKETTEN_OBJECT_LINK">
<column name="DATA" type="VARCHAR(256)" />
</addColumn>
</changeSet>
</databaseChangeLog>
package ch.elexis.core.model;
import javax.persistence.Transient;
import ch.elexis.core.jpa.entities.DbImage;
import ch.elexis.core.jpa.model.adapter.AbstractIdDeleteModelAdapter;
import ch.elexis.core.jpa.model.adapter.AbstractIdModelAdapter;
......@@ -8,6 +10,12 @@ import ch.elexis.core.model.util.internal.ModelUtil;
public class Sticker extends AbstractIdDeleteModelAdapter<ch.elexis.core.jpa.entities.Sticker>
implements IdentifiableWithXid, ISticker {
@Transient
private Identifiable attachedToIdentifiable;
@Transient
private String attachedToData;
public Sticker(ch.elexis.core.jpa.entities.Sticker entity){
super(entity);
}
......@@ -110,4 +118,25 @@ public class Sticker extends AbstractIdDeleteModelAdapter<ch.elexis.core.jpa.ent
public String getLabel(){
return getEntity().getName();
}
@Override
public Identifiable getAttachedTo(){
return attachedToIdentifiable;
}
@Override
public void setAttachedTo(Identifiable identifiable){
this.attachedToIdentifiable = identifiable;
}
@Override
public String getAttachedToData(){
return this.attachedToData;
}
@Override
public void setAttachedToData(String attachedToData){
this.attachedToData = attachedToData;
}
}
package ch.elexis.core.services;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
......@@ -18,7 +18,6 @@ import ch.elexis.core.jpa.entities.StickerObjectLink;
import ch.elexis.core.jpa.entities.StickerObjectLinkId;
import ch.elexis.core.model.ISticker;
import ch.elexis.core.model.Identifiable;
import ch.elexis.core.services.holder.CoreModelServiceHolder;
@Component
public class StickerService implements IStickerService {
......@@ -45,36 +44,56 @@ public class StickerService implements IStickerService {
return em.find(StickerObjectLink.class, new StickerObjectLinkId(id, etikette));
}
/**
* Get all {@link ISticker} linked to the provided object id. The returned list is sorted by
* {@link ISticker#getImportance()}.
*
* @param id
* @return
*/
private List<ISticker> getStickersForId(String id){
List<StickerObjectLink> stickerObjectLinks = getStickerObjectLinksForId(id);
List<ISticker> loadedStickers = stickerObjectLinks
.stream().map(sol -> CoreModelServiceHolder.get()
.load(sol.getEtikette(), ISticker.class).orElse(null))
.filter(Objects::nonNull).collect(Collectors.toList());
loadedStickers.sort(new StickerSorter());
return loadedStickers;
}
@Override
public boolean hasSticker(Identifiable identifiable, ISticker iSticker){
List<StickerObjectLink> entries = findAttachments(identifiable, iSticker);
return entries.isEmpty() ? false : true;
}
private List<StickerObjectLink> findAttachments(Identifiable identifiable, ISticker iSticker){
EntityManager em = (EntityManager) entityManager.getEntityManager(true);
TypedQuery<StickerObjectLink> query =
em.createNamedQuery("StickerObjectLink.obj.etikette", StickerObjectLink.class);
query.setParameter("obj", identifiable.getId());
query.setParameter("etikette", iSticker.getId());
return query.getResultList().isEmpty() ? false : true;
return query.getResultList();
}
@Override
public List<ISticker> getStickers(Identifiable identifiable){
return getStickersForId(identifiable.getId());
List<StickerObjectLink> stickerObjectLinks =
getStickerObjectLinksForId(identifiable.getId());
List<ISticker> loadedStickers = new ArrayList<>();
for (StickerObjectLink link : stickerObjectLinks) {
ISticker sticker = loadStickerForStickerObjectLink(link, identifiable);
if (sticker != null) {
loadedStickers.add(sticker);
}
}
loadedStickers.sort(new StickerSorter());
return loadedStickers;
}
@Override
public ISticker getSticker(Identifiable identifiable, ISticker sticker){
List<StickerObjectLink> resultList = findAttachments(identifiable, sticker);
if (resultList.isEmpty()) {
return null;
}
StickerObjectLink stickerObjectLink = resultList.get(0);
return loadStickerForStickerObjectLink(stickerObjectLink, identifiable);
}
private ISticker loadStickerForStickerObjectLink(StickerObjectLink stickerObjectLink,
Identifiable identifiable){
ISticker sticker =
iModelService.load(stickerObjectLink.getEtikette(), ISticker.class).orElse(null);
if (sticker != null) {
sticker.setAttachedTo(identifiable);
sticker.setAttachedToData(stickerObjectLink.getData());
return sticker;
}
return null;
}
@Override
......@@ -87,12 +106,13 @@ public class StickerService implements IStickerService {
}
@Override
public void addSticker(ISticker sticker, Identifiable identifiable){
public void addSticker(ISticker sticker, Identifiable identifiable, String data){
EntityManager em = (EntityManager) entityManager.getEntityManager(false);
try {
StickerObjectLink link = new StickerObjectLink();
link.setEtikette(sticker.getId());
link.setObj(identifiable.getId());
link.setData(data);
em.getTransaction().begin();
em.merge(link);
......@@ -100,6 +120,12 @@ public class StickerService implements IStickerService {
} finally {
entityManager.closeEntityManager(em);
}
}
@Override
public void addSticker(ISticker sticker, Identifiable identifiable){
addSticker(sticker, identifiable, null);
}
@Override
......
......@@ -289,6 +289,9 @@
<eClassifiers xsi:type="ecore:EClass" name="IDocumentLetter" abstract="true" interface="true"
eSuperTypes="#//IDocument"/>
<eClassifiers xsi:type="ecore:EClass" name="ISticker" abstract="true" interface="true">
<eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
<details key="documentation" value="A sticker is a piece of information that may be attached to an Identifiable. It can either exist for itself, or as an attachedTo (bound to an identifiable) instance."/>
</eAnnotations>
<eOperations name="getLabel" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="background" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="foreground" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
......@@ -296,6 +299,18 @@
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="importance" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EInt"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="image" eType="#//IImage"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="attachedTo" eType="#//Identifiable"
transient="true">
<eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
<details key="documentation" value="If not null this is an attached instance of a sticker. "/>
</eAnnotations>
</eStructuralFeatures>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="attachedToData" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"
transient="true">
<eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
<details key="documentation" value="optionally attached data on an attached sticker instance"/>
</eAnnotations>
</eStructuralFeatures>
<eGenericSuperTypes eClassifier="ecore:EClass types.ecore#//Comparable">
<eTypeArguments eClassifier="#//ISticker"/>
</eGenericSuperTypes>
......
......@@ -225,6 +225,8 @@
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute model.ecore#//ISticker/name"/>
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute model.ecore#//ISticker/importance"/>
<genFeatures notify="false" createChild="false" propertySortChoices="true" ecoreFeature="ecore:EReference model.ecore#//ISticker/image"/>
<genFeatures notify="false" createChild="false" propertySortChoices="true" ecoreFeature="ecore:EReference model.ecore#//ISticker/attachedTo"/>
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute model.ecore#//ISticker/attachedToData"/>
<genOperations ecoreOperation="model.ecore#//ISticker/getLabel"/>
</genClasses>
<genClasses ecoreClass="model.ecore#//ICodeElement">
......
......@@ -15,6 +15,10 @@ package ch.elexis.core.model;
* A representation of the model object '<em><b>ISticker</b></em>'.
* <!-- end-user-doc -->
*
* <!-- begin-model-doc -->
* A sticker is a piece of information that may be attached to an Identifiable. It can either exist for itself, or as an attachedTo (bound to an identifiable) instance.
* <!-- end-model-doc -->
*
* <p>
* The following features are supported:
* </p>
......@@ -25,6 +29,8 @@ package ch.elexis.core.model;
* <li>{@link ch.elexis.core.model.ISticker#getName <em>Name</em>}</li>
* <li>{@link ch.elexis.core.model.ISticker#getImportance <em>Importance</em>}</li>
* <li>{@link ch.elexis.core.model.ISticker#getImage <em>Image</em>}</li>
* <li>{@link ch.elexis.core.model.ISticker#getAttachedTo <em>Attached To</em>}</li>
* <li>{@link ch.elexis.core.model.ISticker#getAttachedToData <em>Attached To Data</em>}</li>
* </ul>
*
* @see ch.elexis.core.model.ModelPackage#getISticker()
......@@ -188,6 +194,56 @@ public interface ISticker extends Comparable<ISticker>, Deleteable, Identifiable
*/
void setImage(IImage value);
/**
* Returns the value of the '<em><b>Attached To</b></em>' reference.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* <!-- begin-model-doc -->
* If not null this is an attached instance of a sticker.
* <!-- end-model-doc -->
* @return the value of the '<em>Attached To</em>' reference.
* @see #setAttachedTo(Identifiable)
* @see ch.elexis.core.model.ModelPackage#getISticker_AttachedTo()
* @model transient="true"
* @generated
*/
Identifiable getAttachedTo();
/**
* Sets the value of the '{@link ch.elexis.core.model.ISticker#getAttachedTo <em>Attached To</em>}' reference.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @param value the new value of the '<em>Attached To</em>' reference.
* @see #getAttachedTo()
* @generated
*/
void setAttachedTo(Identifiable value);
/**
* Returns the value of the '<em><b>Attached To Data</b></em>' attribute.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* <!-- begin-model-doc -->
* optionally attached data on an attached sticker instance
* <!-- end-model-doc -->
* @return the value of the '<em>Attached To Data</em>' attribute.
* @see #setAttachedToData(String)
* @see ch.elexis.core.model.ModelPackage#getISticker_AttachedToData()
* @model transient="true"
* @generated
*/
String getAttachedToData();
/**
* Sets the value of the '{@link ch.elexis.core.model.ISticker#getAttachedToData <em>Attached To Data</em>}' attribute.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @param value the new value of the '<em>Attached To Data</em>' attribute.
* @see #getAttachedToData()
* @generated
*/
void setAttachedToData(String value);
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
......
......@@ -3018,6 +3018,24 @@ public interface ModelPackage extends EPackage {
*/
int ISTICKER__IMAGE = TypesPackage.COMPARABLE_FEATURE_COUNT + 6;
/**
* The feature id for the '<em><b>Attached To</b></em>' reference.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
* @ordered
*/
int ISTICKER__ATTACHED_TO = TypesPackage.COMPARABLE_FEATURE_COUNT + 7;
/**
* The feature id for the '<em><b>Attached To Data</b></em>' attribute.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
* @ordered
*/
int ISTICKER__ATTACHED_TO_DATA = TypesPackage.COMPARABLE_FEATURE_COUNT + 8;
/**
* The number of structural features of the '<em>ISticker</em>' class.
* <!-- begin-user-doc -->
......@@ -3025,7 +3043,7 @@ public interface ModelPackage extends EPackage {
* @generated
* @ordered
*/
int ISTICKER_FEATURE_COUNT = TypesPackage.COMPARABLE_FEATURE_COUNT + 7;
int ISTICKER_FEATURE_COUNT = TypesPackage.COMPARABLE_FEATURE_COUNT + 9;
/**
* The meta object id for the '{@link ch.elexis.core.model.ICodeElement <em>ICode Element</em>}' class.
......@@ -7834,6 +7852,28 @@ public interface ModelPackage extends EPackage {
*/
EReference getISticker_Image();
/**
* Returns the meta object for the reference '{@link ch.elexis.core.model.ISticker#getAttachedTo <em>Attached To</em>}'.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @return the meta object for the reference '<em>Attached To</em>'.
* @see ch.elexis.core.model.ISticker#getAttachedTo()
* @see #getISticker()
* @generated
*/
EReference getISticker_AttachedTo();
/**
* Returns the meta object for the attribute '{@link ch.elexis.core.model.ISticker#getAttachedToData <em>Attached To Data</em>}'.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @return the meta object for the attribute '<em>Attached To Data</em>'.
* @see ch.elexis.core.model.ISticker#getAttachedToData()
* @see #getISticker()
* @generated
*/
EAttribute getISticker_AttachedToData();
/**
* Returns the meta object for class '{@link ch.elexis.core.model.ICodeElement <em>ICode Element</em>}'.
* <!-- begin-user-doc -->
......@@ -11621,6 +11661,22 @@ public interface ModelPackage extends EPackage {
*/
EReference ISTICKER__IMAGE = eINSTANCE.getISticker_Image();
/**
* The meta object literal for the '<em><b>Attached To</b></em>' reference feature.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
EReference ISTICKER__ATTACHED_TO = eINSTANCE.getISticker_AttachedTo();
/**
* The meta object literal for the '<em><b>Attached To Data</b></em>' attribute feature.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
EAttribute ISTICKER__ATTACHED_TO_DATA = eINSTANCE.getISticker_AttachedToData();
/**
* The meta object literal for the '{@link ch.elexis.core.model.ICodeElement <em>ICode Element</em>}' class.
* <!-- begin-user-doc -->
......
......@@ -1998,6 +1998,26 @@ public class ModelPackageImpl extends EPackageImpl implements ModelPackage {
return (EReference)iStickerEClass.getEStructuralFeatures().get(5);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public EReference getISticker_AttachedTo() {
return (EReference)iStickerEClass.getEStructuralFeatures().get(6);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public EAttribute getISticker_AttachedToData() {
return (EAttribute)iStickerEClass.getEStructuralFeatures().get(7);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
......@@ -4595,6 +4615,8 @@ public class ModelPackageImpl extends EPackageImpl implements ModelPackage {
createEAttribute(iStickerEClass, ISTICKER__NAME);
createEAttribute(iStickerEClass, ISTICKER__IMPORTANCE);
createEReference(iStickerEClass, ISTICKER__IMAGE);
createEReference(iStickerEClass, ISTICKER__ATTACHED_TO);
createEAttribute(iStickerEClass, ISTICKER__ATTACHED_TO_DATA);
iCodeElementEClass = createEClass(ICODE_ELEMENT);
createEAttribute(iCodeElementEClass, ICODE_ELEMENT__CODE);
......@@ -5268,6 +5290,8 @@ public class ModelPackageImpl extends EPackageImpl implements ModelPackage {
initEAttribute(getISticker_Name(), ecorePackage.getEString(), "name", null, 0, 1, ISticker.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
initEAttribute(getISticker_Importance(), ecorePackage.getEInt(), "importance", null, 0, 1, ISticker.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
initEReference(getISticker_Image(), this.getIImage(), null, "image", null, 0, 1, ISticker.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_COMPOSITE, IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
initEReference(getISticker_AttachedTo(), this.getIdentifiable(), null, "attachedTo", null, 0, 1, ISticker.class, IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_COMPOSITE, IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
initEAttribute(getISticker_AttachedToData(), ecorePackage.getEString(), "attachedToData", null, 0, 1, ISticker.class, IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
addEOperation(iStickerEClass, ecorePackage.getEString(), "getLabel", 0, 1, IS_UNIQUE, IS_ORDERED);
......
......@@ -18,7 +18,8 @@ public interface IStickerService {
public boolean hasSticker(Identifiable identifiable, ISticker iSticker);
/**
* Get all stickers for the {@link Identifiable}.
* Get all stickers for the {@link Identifiable}. The returned list is sorted by
* {@link ISticker#getImportance()}.
*
* @param identifiable
* @return
......@@ -33,7 +34,39 @@ public interface IStickerService {
*/
public Optional<ISticker> getSticker(Identifiable identifiable);
public void addSticker(ISticker sticker, Identifiable identifiable);
/**
* Get the attached instance of the given sticker on identifiable, if it exists
*
* @param identifiable
* @param sticker
* @return the attached instance, with {@link ISticker#getAttachedTo()} being non
* <code>null</code>
*/
public ISticker getSticker(Identifiable identifiable, ISticker sticker);
/**
* Add a sticker to a given identifiable with optional detail data. There can only exist on
* attachment of a given sticker to identifiable, so multiple calls overwrite the existing.
*
* @param sticker
* to apply
* @param identifiable
* to apply the sticker to
* @param <code>null</code>
* or data which only applies to this specific sticker/identifiable attachment
*/
public void addSticker(ISticker sticker, Identifiable identifiable, String data);
/**
* Add a sticker to a given identifiable
*
* @param sticker
* @param identifiable
* @see IStickerService#addSticker(ISticker, Identifiable, String)
*/
default void addSticker(ISticker sticker, Identifiable identifiable){
addSticker(sticker, identifiable, null);
}
public void removeSticker(ISticker sticker, Identifiable identifiable);
......
......@@ -3,6 +3,7 @@ package ch.elexis.core.services;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.util.List;
......@@ -19,23 +20,25 @@ import ch.elexis.core.test.TestEntities;
import ch.elexis.core.utils.OsgiServiceUtil;
public class IStickerServiceTest extends AbstractServiceTest {
private IStickerService service = OsgiServiceUtil.getService(IStickerService.class).get();
@Test
public void getStickers() {
Optional<IPatient> load = coreModelService.load(TestEntities.PATIENT_MALE_ID, IPatient.class);
public void getStickers(){
Optional<IPatient> load =
coreModelService.load(TestEntities.PATIENT_MALE_ID, IPatient.class);
List<ISticker> stickers = service.getStickers(load.get());
assertEquals(2, stickers.size());
}
@Test
public void getSticker() {
Optional<IPatient> load = coreModelService.load(TestEntities.PATIENT_MALE_ID, IPatient.class);
public void getSticker(){
Optional<IPatient> load =
coreModelService.load(TestEntities.PATIENT_MALE_ID, IPatient.class);
Optional<ISticker> sticker = service.getSticker(load.get());
assertEquals("verstorben", sticker.get().getName());
}
@Test
public void addSticker(){
Optional<IPatient> patient =
......@@ -74,58 +77,57 @@ public class IStickerServiceTest extends AbstractServiceTest {
assertFalse(service.hasSticker(patient.get(), newSticker));
}
@Ignore(value="Not yet implemented the required mapping")
@Ignore(value = "Not yet implemented the required mapping")
@Test
public void isStickerAddableToClass() {
public void isStickerAddableToClass(){
ISticker sticker = coreModelService.load("T3811f3656cea91c2080136", ISticker.class).get();
assertTrue(service.isStickerAddableToClass(IPatient.class, sticker));
}
//
// @Test
// public void testCreateAndDeleteSticker() {
// // creates a sticker
// Sticker sticker = new Sticker();
// sticker.setBackground("0");
// sticker.setForeground("0");
// sticker.setName("Sticker 2");
//
// StickerClassLink stickerClassLink = new StickerClassLink();
// stickerClassLink.setObjclass(ArtikelstammItem.class.getSimpleName());
// stickerClassLink.setSticker(sticker);
// sticker.getStickerClassLinks().add(stickerClassLink);
//
// StickerObjectLink stickerObjectLink = new StickerObjectLink();
// stickerObjectLink.setObj(Artikel.class.getSimpleName());
// stickerObjectLink.setSticker(sticker);
//
// sticker.getStickerObjectLinks().add(stickerObjectLink);
//
// sticker = StickerService.save(sticker);
//
// assertEquals(1, StickerService.findAll(Sticker.class, false).size());
// assertEquals("Sticker 2", sticker.getName());
// assertEquals("0", sticker.getBackground());
// assertEquals(1, sticker.getStickerClassLinks().size());
// assertEquals(1, sticker.getStickerObjectLinks().size());
// for (StickerClassLink stLink : sticker.getStickerClassLinks()) {
// assertEquals(ArtikelstammItem.class.getSimpleName(), stLink.getObjclass());
// assertEquals(stLink.getSticker().getId(), sticker.getId());
// }
// for (StickerObjectLink stLink : sticker.getStickerObjectLinks()) {
// assertEquals(Artikel.class.getSimpleName(), stLink.getObj());
// assertEquals(stLink.getSticker().getId(), sticker.getId());
// }
//
// // removes a sticker
// StickerService.delete(StickerService.load(sticker.getId()).get());
// assertEquals(0, StickerService.findAll(Sticker.class, false).size());
// assertEquals(1, StickerService.findAll(Sticker.class, true).size());
// }
//
//
// @Test
// public void testCreateAndDeleteSticker() {
// // creates a sticker
// Sticker sticker = new Sticker();
// sticker.setBackground("0");
// sticker.setForeground("0");
// sticker.setName("Sticker 2");
//
// StickerClassLink stickerClassLink = new StickerClassLink();
// stickerClassLink.setObjclass(ArtikelstammItem.class.getSimpleName());
// stickerClassLink.setSticker(sticker);
// sticker.getStickerClassLinks().add(stickerClassLink);
//
// StickerObjectLink stickerObjectLink = new StickerObjectLink();
// stickerObjectLink.setObj(Artikel.class.getSimpleName());
// stickerObjectLink.setSticker(sticker);
//
// sticker.getStickerObjectLinks().add(stickerObjectLink);
//
// sticker = StickerService.save(sticker);
//
// assertEquals(1, StickerService.findAll(Sticker.class, false).size());
// assertEquals("Sticker 2", sticker.getName());
// assertEquals("0", sticker.getBackground());
// assertEquals(1, sticker.getStickerClassLinks().size());
// assertEquals(1, sticker.getStickerObjectLinks().size());
// for (StickerClassLink stLink : sticker.getStickerClassLinks()) {
// assertEquals(ArtikelstammItem.class.getSimpleName(), stLink.getObjclass());
// assertEquals(stLink.getSticker().getId(), sticker.getId());
// }
// for (StickerObjectLink stLink : sticker.getStickerObjectLinks()) {
// assertEquals(Artikel.class.getSimpleName(), stLink.getObj());
// assertEquals(stLink.getSticker().getId(), sticker.getId());
// }
//
// // removes a sticker
// StickerService.delete(StickerService.load(sticker.getId()).get());
// assertEquals(0, StickerService.findAll(Sticker.class, false).size());
// assertEquals(1, StickerService.findAll(Sticker.class, true).size());
// }
//
@Test
public void testFindStickersApplicableToPatients(){
public void findStickersApplicableToPatients(){
ISticker newSticker = coreModelService.create(ISticker.class);
newSticker.setName("Sticker 2");
coreModelService.save(newSticker);
......@@ -136,37 +138,67 @@ public class IStickerServiceTest extends AbstractServiceTest {
assertFalse(service.isStickerAddableToClass(IArticle.class, newSticker));
assertFalse(service.isStickerAddableToClass(IOrganization.class, newSticker));
}
//
// @Test
// public void testApplyRemoveStickerToPatient() {
//
// Sticker sticker = new StickerService.StickerBuilder("Sticker 2", "123456", "123456", ElexisTypeMap.TYPE_PATIENT)
// .buildAndSave();
//
// assertEquals(1, StickerService.findAll(Sticker.class, false).size());
// assertEquals("Sticker 2", sticker.getName());
// assertEquals(1, sticker.getStickerClassLinks().size());
// assertEquals(ElexisTypeMap.TYPE_PATIENT, sticker.getStickerClassLinks().iterator().next().getObjclass());
// Optional<Kontakt> findById = KontaktService.load(TestEntities.PATIENT_MALE_ID);
//
// List<Sticker> findStickersOnObject = StickerService.findStickersOnObject(findById.get());
// assertEquals(0, findStickersOnObject.size());
//
// boolean stickerApplied = StickerService.applyStickerToObject(sticker, findById.get());
// assertTrue(stickerApplied);
// // deliberately try twice to see that the sum still is 1
// stickerApplied = StickerService.applyStickerToObject(sticker, findById.get());
// assertTrue(stickerApplied);
//
// findStickersOnObject = StickerService.findStickersOnObject(findById.get());
// assertEquals(1, findStickersOnObject.size());
//
// StickerService.removeAllStickersFromObject(findById.get());
//
// findStickersOnObject = StickerService.findStickersOnObject(findById.get());
// assertEquals(0, findStickersOnObject.size());
//
// StickerService.remove(sticker);
// }
@Test