Search in sources :

Example 11 with Transactional

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.");
}
Also used : FaReportDocumentEntity(eu.europa.ec.fisheries.ers.fa.entities.FaReportDocumentEntity) FluxFaReportMessageEntity(eu.europa.ec.fisheries.ers.fa.entities.FluxFaReportMessageEntity) ParseException(com.vividsolutions.jts.io.ParseException) ServiceException(eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException) Transactional(javax.transaction.Transactional)

Example 12 with Transactional

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);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) MessageUriPojo(won.owner.pojo.MessageUriPojo) User(won.owner.model.User) Authentication(org.springframework.security.core.Authentication) WonMessage(won.protocol.message.WonMessage) URI(java.net.URI) WonMessageSenderException(won.protocol.message.sender.exception.WonMessageSenderException) WonMessageProcessingException(won.protocol.exception.WonMessageProcessingException) Transactional(javax.transaction.Transactional) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 13 with Transactional

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";
}
Also used : ObjectError(org.springframework.validation.ObjectError) LoginUser(com.dappermoose.stsimplefinance.data.LoginUser) Transactional(javax.transaction.Transactional) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 14 with Transactional

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;
}
Also used : ModelCardWrapperDto(org.collectiveone.modules.model.dto.ModelCardWrapperDto) Transactional(javax.transaction.Transactional)

Example 15 with Transactional

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;
}
Also used : ModelSectionDto(org.collectiveone.modules.model.dto.ModelSectionDto) Transactional(javax.transaction.Transactional)

Aggregations

Transactional (javax.transaction.Transactional)314 Test (org.junit.Test)100 PostResult (org.collectiveone.common.dto.PostResult)29 ArrayList (java.util.ArrayList)25 UserDO (org.neusoft.neubbs.entity.UserDO)21 Timestamp (java.sql.Timestamp)18 TopicDO (org.neusoft.neubbs.entity.TopicDO)18 Initiative (org.collectiveone.modules.initiatives.Initiative)16 GetResult (org.collectiveone.common.dto.GetResult)15 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)13 TopicReplyDO (org.neusoft.neubbs.entity.TopicReplyDO)13 HashMap (java.util.HashMap)12 Date (java.util.Date)11 AppUser (org.collectiveone.modules.users.AppUser)11 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)11 UUID (java.util.UUID)10 RolesAllowed (javax.annotation.security.RolesAllowed)10 PeerReviewedAssignation (org.collectiveone.modules.assignations.evaluationlogic.PeerReviewedAssignation)10 IOException (java.io.IOException)9 Booking (org.apache.karaf.examples.jpa.Booking)9