Search in sources :

Example 1 with Transactional

use of javax.transaction.Transactional in project ORCID-Source by ORCID.

the class AddressManagerImpl method deleteAddress.

@Override
@Transactional
public boolean deleteAddress(String orcid, Long putCode) {
    AddressEntity entity = addressDao.getAddress(orcid, putCode);
    orcidSecurityManager.checkSource(entity);
    try {
        addressDao.remove(entity);
    } catch (Exception e) {
        return false;
    }
    return true;
}
Also used : AddressEntity(org.orcid.persistence.jpa.entities.AddressEntity) ApplicationException(org.orcid.core.exception.ApplicationException) OrcidDuplicatedElementException(org.orcid.core.exception.OrcidDuplicatedElementException) Transactional(javax.transaction.Transactional)

Example 2 with Transactional

use of javax.transaction.Transactional in project zhcet-web by zhcet-amu.

the class EmailVerificationService method sendMail.

/**
 * Sends mail to the user to be verified and saves the user with the email and status to be unverified
 * Also, publishes an event notifying the same
 * @param token {@link VerificationToken} token to be sent email with respect to
 */
@Transactional
public void sendMail(VerificationToken token) {
    String relativeUrl = "/login/email/verify?auth=" + token.getToken();
    log.debug("Verification link generated : {}", relativeUrl);
    linkMailService.sendEmail(getPayLoad(token.getEmail(), token.getUser(), relativeUrl), false);
    // Now we set the email to the user and disable email verified
    User user = token.getUser();
    log.debug("Saving user email {} -> {}", user.getUserId(), token.getEmail());
    user.setEmail(token.getEmail());
    user.setEmailVerified(false);
    userService.save(user);
    log.debug("Saved user email");
    eventPublisher.publishEvent(new EmailVerifiedEvent(user));
}
Also used : User(amu.zhcet.data.user.User) Transactional(javax.transaction.Transactional)

Example 3 with Transactional

use of javax.transaction.Transactional in project ORCID-Source by ORCID.

the class ManageMembersControllerTest method createMemberProfileWithInvalidEmailsTest.

@Test
@Transactional
public void createMemberProfileWithInvalidEmailsTest() throws Exception {
    ProfileEntity profile = profileDao.find("5555-5555-5555-0000");
    assertNotNull(profile);
    assertNotNull(profile.getPrimaryEmail());
    String existingEmail = profile.getPrimaryEmail().getId();
    assertNotNull(existingEmail);
    Member group = new Member();
    group.setGroupName(Text.valueOf("Group Name"));
    group.setType(Text.valueOf("basic"));
    group.setSalesforceId(Text.valueOf(""));
    // Validate already existing email address
    group.setEmail(Text.valueOf(existingEmail));
    group = manageMembers.createMember(group);
    assertEquals(1, group.getErrors().size());
    assertEquals(manageMembers.getMessage("group.email.already_used", new ArrayList<String>()), group.getErrors().get(0));
    // Validate empty email address
    group.setEmail(Text.valueOf(""));
    group = manageMembers.createMember(group);
    assertEquals(1, group.getErrors().size());
    assertEquals(manageMembers.getMessage("NotBlank.group.email", new ArrayList<String>()), group.getErrors().get(0));
    // Validate invalid email address
    group.setEmail(Text.valueOf("invalidemail"));
    group = manageMembers.createMember(group);
    assertEquals(1, group.getErrors().size());
    assertEquals(manageMembers.getMessage("group.email.invalid_email", new ArrayList<String>()), group.getErrors().get(0));
}
Also used : ArrayList(java.util.ArrayList) Member(org.orcid.pojo.ajaxForm.Member) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test) Transactional(javax.transaction.Transactional)

Example 4 with Transactional

use of javax.transaction.Transactional in project ORCID-Source by ORCID.

the class AddressManagerImpl method deleteAddress.

@Override
@Transactional
public boolean deleteAddress(String orcid, Long putCode) {
    AddressEntity entity = addressDao.getAddress(orcid, putCode);
    orcidSecurityManager.checkSource(entity);
    try {
        addressDao.remove(entity);
    } catch (Exception e) {
        return false;
    }
    return true;
}
Also used : AddressEntity(org.orcid.persistence.jpa.entities.AddressEntity) ApplicationException(org.orcid.core.exception.ApplicationException) OrcidDuplicatedElementException(org.orcid.core.exception.OrcidDuplicatedElementException) Transactional(javax.transaction.Transactional)

Example 5 with Transactional

use of javax.transaction.Transactional in project ORCID-Source by ORCID.

the class ProfileKeywordManagerImpl method updateKeyword.

@Override
@Transactional
public Keyword updateKeyword(String orcid, Long putCode, Keyword keyword, boolean isApiRequest) {
    SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
    ProfileKeywordEntity updatedEntity = profileKeywordDao.getProfileKeyword(orcid, putCode);
    Visibility originalVisibility = Visibility.fromValue(updatedEntity.getVisibility().value());
    // Save the original source
    String existingSourceId = updatedEntity.getSourceId();
    String existingClientSourceId = updatedEntity.getClientSourceId();
    // Validate the keyword
    PersonValidator.validateKeyword(keyword, sourceEntity, false, isApiRequest, originalVisibility);
    // Validate it is not duplicated
    List<ProfileKeywordEntity> existingKeywords = profileKeywordDao.getProfileKeywords(orcid, getLastModified(orcid));
    for (ProfileKeywordEntity existing : existingKeywords) {
        if (isDuplicated(existing, keyword, sourceEntity)) {
            Map<String, String> params = new HashMap<String, String>();
            params.put("type", "keyword");
            params.put("value", keyword.getContent());
            throw new OrcidDuplicatedElementException(params);
        }
    }
    orcidSecurityManager.checkSource(updatedEntity);
    adapter.toProfileKeywordEntity(keyword, updatedEntity);
    updatedEntity.setLastModified(new Date());
    // Be sure it doesn't overwrite the source
    updatedEntity.setSourceId(existingSourceId);
    updatedEntity.setClientSourceId(existingClientSourceId);
    profileKeywordDao.merge(updatedEntity);
    return adapter.toKeyword(updatedEntity);
}
Also used : ProfileKeywordEntity(org.orcid.persistence.jpa.entities.ProfileKeywordEntity) HashMap(java.util.HashMap) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) OrcidDuplicatedElementException(org.orcid.core.exception.OrcidDuplicatedElementException) Visibility(org.orcid.jaxb.model.v3.dev1.common.Visibility) Date(java.util.Date) Transactional(javax.transaction.Transactional)

Aggregations

Transactional (javax.transaction.Transactional)299 Test (org.junit.Test)99 PostResult (org.collectiveone.common.dto.PostResult)29 ArrayList (java.util.ArrayList)24 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 UUID (java.util.UUID)10 RolesAllowed (javax.annotation.security.RolesAllowed)10 PeerReviewedAssignation (org.collectiveone.modules.assignations.evaluationlogic.PeerReviewedAssignation)10 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)10 IOException (java.io.IOException)9 TopicContentDO (org.neusoft.neubbs.entity.TopicContentDO)9