use of javax.transaction.Transactional in project UVMS-ActivityModule-APP by UnionVMS.
the class FluxMessageServiceBean method saveFishingActivityReportDocuments.
/**
* {@inheritDoc}
*/
@Override
@Transactional(Transactional.TxType.REQUIRED)
public void saveFishingActivityReportDocuments(FLUXFAReportMessage faReportMessage, FaReportSourceEnum faReportSourceEnum) throws ServiceException {
log.info("[INFO] Going to save [ " + faReportMessage.getFAReportDocuments().size() + " ] FaReportDocuments..");
FluxFaReportMessageEntity messageEntity = FluxFaReportMessageMapper.INSTANCE.mapToFluxFaReportMessage(faReportMessage, faReportSourceEnum, new FluxFaReportMessageEntity());
final Set<FaReportDocumentEntity> faReportDocuments = messageEntity.getFaReportDocuments();
for (FaReportDocumentEntity faReportDocument : faReportDocuments) {
try {
updateGeometry(faReportDocument);
enrichFishingActivityWithGuiID(faReportDocument);
} catch (Exception e) {
log.error("Could not update Geometry OR enrichActivities for faReportDocument:" + faReportDocument.getId());
}
}
log.debug("fishing activity records to be saved : " + faReportDocuments.size());
fluxReportMessageDao.saveFluxFaReportMessage(messageEntity);
log.debug("Save partial FluxFaReportMessage before further processing");
updateFaReportCorrections(faReportMessage.getFAReportDocuments());
log.debug("Update FaReport Corrections is complete.");
updateFishingTripStartAndEndDate(faReportDocuments);
log.info("FluxFaReportMessage Saved successfully.");
}
use of javax.transaction.Transactional in project webofneeds by researchstudio-sat.
the class RestMessageController method send.
/**
* Prepares and sends the WonMessage received in the body of this post request.
* The message has to be encoded in JSON-LD and use the reserved self message
* URI.
*
* @param message
* @return
*/
@Transactional
@RequestMapping(value = "/send", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.POST, consumes = "application/ld+json")
public ResponseEntity send(@RequestBody String serializedWonMessage) {
String username = SecurityContextHolder.getContext().getAuthentication().getName();
if (username == null) {
return generateStatusResponse(RestStatusResponse.USER_NOT_SIGNED_IN, Optional.empty());
}
final Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
WonMessage msg = null;
// decode the message
try {
msg = WonMessageDecoder.decode(Lang.JSONLD, serializedWonMessage);
} catch (Exception e) {
logger.debug("Error parsing message, returning error response", e);
return generateStatusResponse(RestStatusResponse.ERROR_PARSING_MESSAGE, Optional.of(getErrorMessage(e)));
}
// prepare it
try {
AuthenticationThreadLocal.setAuthentication(authentication);
msg = ownerApplicationService.prepareMessage(msg);
} catch (Exception e) {
logger.debug("Error preparing message, returning error response", e);
return generateStatusResponse(RestStatusResponse.ERROR_PREPARING_MESSAGE, Optional.of(getErrorMessage(e)));
} finally {
// be sure to remove the principal from the threadlocal
AuthenticationThreadLocal.remove();
}
// associate all the user's websocket sessions with
// the sender atom so that we can route the response properly
User user = getUser(authentication, msg);
URI atomURI = msg.getSenderAtomURI();
if (user != null && atomURI != null) {
webSocketSessionService.getWebSocketSessions(user).forEach(session -> webSocketSessionService.addMapping(atomURI, session));
this.userAtomService.updateUserAtomAssociation(msg, user);
}
// send it in a separate thread (so we can return our result immediately)
try {
final WonMessage preparedMessage = msg;
if (msg.getMessageType() == WonMessageType.DELETE) {
try {
userAtomService.setAtomDeleted(atomURI);
} catch (Exception e) {
logger.debug("Could not delete atom with uri {} because of {}", atomURI, e);
}
}
executor.submit(() -> {
ownerApplicationService.sendMessage(preparedMessage);
});
} catch (Exception e) {
logger.debug("Error sending message, returning error response", e);
return generateStatusResponse(RestStatusResponse.ERROR_SENDING_MESSAGE_TO_NODE, Optional.of(getErrorMessage(e)));
}
return new ResponseEntity(new MessageUriPojo(msg.getMessageURIRequired().toString()), HttpStatus.OK);
}
use of javax.transaction.Transactional in project spring-thymeleaf-simplefinance by heitkergm.
the class RegisterAction method processRegisterAction.
/**
* Process register action.
*
* @param register the register
* @param res the res
* @param model the model
* @param request the request
* @return the string
*/
@Transactional
@RequestMapping(value = "/register", method = RequestMethod.POST)
public String processRegisterAction(@Valid @ModelAttribute("register") final RegisterUser register, final BindingResult res, final Model model, final HttpServletRequest request) {
if (res.hasErrors()) {
model.addAttribute("register", register);
model.addAttribute("tzones", context.getBean("tzones"));
return "register";
}
// check if the user already exists
final List<LoginUser> users = userRepository.findByUserName(register.getUserName());
if (users.size() > 0) {
final ObjectError objErr = new ObjectError("RegisterUser", messageSource.getMessage("register.duplicateUser", null, request.getLocale()));
res.addError(objErr);
model.addAttribute("register", register);
model.addAttribute("tzones", context.getBean("tzones"));
return "register";
}
// create user bean
final LoginUser user = new LoginUser();
user.setUserName(register.getUserName());
user.setPassword(register.getPassword());
user.setTzone(register.getTzone());
userRepository.save(user);
return "redirect:/main";
}
use of javax.transaction.Transactional in project CollectiveOneWebapp by CollectiveOne.
the class ModelService method addSectionSubElements.
@Transactional
public ModelSectionDto addSectionSubElements(ModelSectionDto sectionDto, UUID sectionId, Integer level, UUID requestByUserId) {
ModelSection section = modelSectionRepository.findById(sectionId);
if (level >= 1) {
sectionDto.setSubElementsLoaded(true);
for (ModelCardWrapper cardWrapper : section.getCardsWrappers()) {
ModelCardWrapperDto cardWrapperDto = cardWrapper.toDto();
cardWrapperDto.setnLikes(cardLikeRepository.countOfCard(cardWrapper.getId()));
if (requestByUserId != null) {
cardWrapperDto.setUserLiked(cardLikeRepository.findByCardWrapperIdAndAuthor_c1Id(cardWrapper.getId(), requestByUserId) != null);
}
List<ModelSection> inSections = modelCardWrapperRepository.findParentSections(cardWrapper.getId());
for (ModelSection inSection : inSections) {
cardWrapperDto.getInSections().add(inSection.toDto());
}
sectionDto.getCardsWrappers().add(cardWrapperDto);
}
for (ModelSection subsection : section.getSubsections()) {
sectionDto.getSubsections().add(addSectionSubElements(subsection.toDto(), subsection.getId(), level - 1, requestByUserId));
}
} else {
sectionDto.setSubElementsLoaded(false);
}
return sectionDto;
}
use of javax.transaction.Transactional in project CollectiveOneWebapp by CollectiveOne.
the class ModelService method getSectionDto.
@Transactional
public ModelSectionDto getSectionDto(UUID sectionId, Integer level, UUID requestByUserId) {
ModelSection section = modelSectionRepository.findById(sectionId);
ModelSectionDto sectionDto = section.toDto();
/* set parent sections or views */
List<ModelSection> inSections = modelSectionRepository.findParentSections(section.getId());
List<ModelView> inViews = modelSectionRepository.findParentViews(section.getId());
for (ModelSection inSection : inSections) {
sectionDto.getInSections().add(inSection.toDto());
}
for (ModelView inView : inViews) {
sectionDto.getInViews().add(inView.toDto());
}
sectionDto = addSectionSubElements(sectionDto, section.getId(), level, requestByUserId);
return sectionDto;
}
Aggregations