@Service public class BusApprovedElementRepository extends java.lang.Object implements BusApprovedElementInterface
Supported items:
Modifier and Type | Field and Description |
---|---|
private BusInterface |
busRepository |
private static BusApprovedElementRepository |
instance |
private JacksonMapper |
mapper |
Constructor and Description |
---|
BusApprovedElementRepository()
Spring implementation of Singleton Pattern
|
Modifier and Type | Method and Description |
---|---|
RichPointerBus |
fromElementToRichPointerBus(Element element)
This method maps Element to RichPointerBus to send it to bus, with a create or a update.
|
Element |
fromRichPointerBusToElement(RichPointerBus pointer)
this method gets from RichPointerBus, typically received from the bus after an Update or a create action,
and maps it to an Element like MeasurementGoal, Metric, Question.
|
<T extends Element> |
getApprovedElement(PointerBus pointerBus,
java.lang.Class<T> clazz)
This function gathers Elements like MeasurementGoal, Metric and Question from the bus.
|
<T extends Element> |
getApprovedElements(PointerBus pointerBus,
java.lang.Class<T> clazz)
This function gathers an Array of Elements like MeasurementGoal, Metric and Question from the bus.
|
static BusApprovedElementRepository |
getInstance()
this getter has to be used only when is not possible the IoD of Spring, like commands of State Transition Utils.
|
<T extends Element> |
getLastApprovedElement(java.lang.String id,
java.lang.Class<T> clazz,
Entity typeObj)
this function returns the last approved version of element with a id in the bus
|
<T extends Element> |
sendApprovedElement(Element element,
java.lang.Class<T> clazz)
This function send an approved Element like to Bus.
|
@Autowired private BusInterface busRepository
@Autowired private JacksonMapper mapper
@Autowired private static BusApprovedElementRepository instance
public BusApprovedElementRepository()
public static BusApprovedElementRepository getInstance()
public <T extends Element> Element sendApprovedElement(@Nonnull Element element, java.lang.Class<T> clazz) throws BadInputException, BusException, java.io.IOException
sendApprovedElement
in interface BusApprovedElementInterface
element
- the Element to send to busclazz
- is the class of the element, like MeasurementGoal or QuestionBadInputException
- state not "Approved"BusException
- error in interation with busjava.io.IOException
- generic error mapping entitiespublic <T extends Element> T getApprovedElement(@Nonnull PointerBus pointerBus, java.lang.Class<T> clazz) throws BadInputException, BusException, java.io.IOException
getApprovedElement
in interface BusApprovedElementInterface
pointerBus
- the pointer of the entity requestedclazz
- the class of the element to gather, like MeasurementGoal.class, Metric.classBadInputException
- if the pointer is not correctBusException
- error in interation with busjava.io.IOException
- generic mapping error.public <T extends Element> T getLastApprovedElement(@Nonnull java.lang.String id, java.lang.Class<T> clazz, Entity typeObj) throws BadInputException, BusException, java.io.IOException
getLastApprovedElement
in interface BusApprovedElementInterface
id
- clazz
- BadInputException
BusException
java.io.IOException
public <T extends Element> java.util.ArrayList<T> getApprovedElements(@Nonnull PointerBus pointerBus, java.lang.Class<T> clazz) throws BadInputException, BusException, java.io.IOException
getApprovedElements
in interface BusApprovedElementInterface
pointerBus
- the pointer of the entity requestedclazz
- the class of the element to gather, like MeasurementGoal.class, Metric.classBadInputException
- if the pointer is not correctBusException
- error in interation with busjava.io.IOException
- generic mapping error.public RichPointerBus fromElementToRichPointerBus(Element element) throws com.fasterxml.jackson.core.JsonProcessingException
TODO: change secure key in something safer (my idea is make a secret password in file /resource/application.properties. To generate this secret token we can do MD5(password XOR id)) In this way we have only to know the password, and not all the secret tokens.
fromElementToRichPointerBus
in interface BusApprovedElementInterface
element
- typically is of type MeasurementGoal, Metric or Question. Cast to Element is not necessary.com.fasterxml.jackson.core.JsonProcessingException
- if the ObjectToString mapping is not possiblepublic Element fromRichPointerBusToElement(RichPointerBus pointer) throws BusException, java.io.IOException
fromRichPointerBusToElement
in interface BusApprovedElementInterface
pointer,
- typically received from bus. It Must contain fields getTypeObj and payload not nullBusException
- if typeobject is not correct, or supported. Exception message contains the value that triggers exceptionjava.io.IOException
- if the StringToObject is not possible