Search in sources :

Example 1 with EclipseData

use of org.eclipse.openvsx.entities.EclipseData in project openvsx by eclipse.

the class EclipseServiceTest method testGetPublisherAgreementNotFound.

@Test
public void testGetPublisherAgreementNotFound() throws Exception {
    var user = mockUser();
    var eclipseData = new EclipseData();
    user.setEclipseData(eclipseData);
    eclipseData.personId = "test";
    Mockito.when(restTemplate.exchange(any(RequestEntity.class), eq(String.class))).thenThrow(new HttpClientErrorException(HttpStatus.NOT_FOUND));
    var agreement = eclipse.getPublisherAgreement(user);
    assertThat(agreement).isNull();
}
Also used : HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) RequestEntity(org.springframework.http.RequestEntity) EclipseData(org.eclipse.openvsx.entities.EclipseData) Test(org.junit.jupiter.api.Test)

Example 2 with EclipseData

use of org.eclipse.openvsx.entities.EclipseData in project openvsx by eclipse.

the class EclipseServiceTest method testRevokePublisherAgreementByAdmin.

@Test
public void testRevokePublisherAgreementByAdmin() throws Exception {
    var user = mockUser();
    var eclipseData = new EclipseData();
    user.setEclipseData(eclipseData);
    eclipseData.personId = "test";
    eclipseData.publisherAgreement = new EclipseData.PublisherAgreement();
    eclipseData.publisherAgreement.isActive = true;
    var admin = new UserData();
    admin.setLoginName("admin");
    admin.setEclipseToken(new AuthToken());
    admin.getEclipseToken().accessToken = "67890";
    Mockito.when(tokens.getActiveToken(admin, "eclipse")).thenReturn(admin.getEclipseToken());
    eclipse.revokePublisherAgreement(user, admin);
    assertThat(user.getEclipseData().publisherAgreement.isActive).isFalse();
}
Also used : UserData(org.eclipse.openvsx.entities.UserData) AuthToken(org.eclipse.openvsx.entities.AuthToken) EclipseData(org.eclipse.openvsx.entities.EclipseData) Test(org.junit.jupiter.api.Test)

Example 3 with EclipseData

use of org.eclipse.openvsx.entities.EclipseData in project openvsx by eclipse.

the class EclipseService method updateEclipseData.

/**
 * Update the Eclipse data of the given user and commit the change to the database.
 */
protected <T> T updateEclipseData(UserData user, Function<EclipseData, T> update, Consumer<EclipseData> initialize) {
    return transactions.execute(status -> {
        EclipseData eclipseData;
        if (user.getEclipseData() == null) {
            eclipseData = new EclipseData();
            initialize.accept(eclipseData);
        } else {
            // We need to clone and reset the data to ensure that Hibernate will persist the updated state
            eclipseData = user.getEclipseData().clone();
        }
        var result = update.apply(eclipseData);
        user.setEclipseData(eclipseData);
        entityManager.merge(user);
        return result;
    });
}
Also used : EclipseData(org.eclipse.openvsx.entities.EclipseData)

Example 4 with EclipseData

use of org.eclipse.openvsx.entities.EclipseData in project openvsx by eclipse.

the class EclipseService method updateUserData.

/**
 * Update the given user data with a profile obtained from Eclipse API.
 */
@Transactional
public EclipseData updateUserData(UserData user, EclipseProfile profile) {
    EclipseData eclipseData;
    if (user.getEclipseData() == null) {
        eclipseData = new EclipseData();
    } else {
        // We need to clone and reset the data to ensure that Hibernate will persist the updated state
        eclipseData = user.getEclipseData().clone();
    }
    if (Strings.isNullOrEmpty(eclipseData.personId)) {
        eclipseData.personId = profile.name;
    }
    if (profile.publisherAgreements != null) {
        if (profile.publisherAgreements.openVsx == null) {
            if (eclipseData.publisherAgreement != null) {
                eclipseData.publisherAgreement.isActive = false;
            }
        } else if (!Strings.isNullOrEmpty(profile.publisherAgreements.openVsx.version)) {
            if (eclipseData.publisherAgreement == null) {
                eclipseData.publisherAgreement = new EclipseData.PublisherAgreement();
            }
            eclipseData.publisherAgreement.isActive = true;
            eclipseData.publisherAgreement.version = profile.publisherAgreements.openVsx.version;
        }
    }
    user.setEclipseData(eclipseData);
    entityManager.merge(user);
    return eclipseData;
}
Also used : EclipseData(org.eclipse.openvsx.entities.EclipseData) Transactional(javax.transaction.Transactional)

Aggregations

EclipseData (org.eclipse.openvsx.entities.EclipseData)4 Test (org.junit.jupiter.api.Test)2 Transactional (javax.transaction.Transactional)1 AuthToken (org.eclipse.openvsx.entities.AuthToken)1 UserData (org.eclipse.openvsx.entities.UserData)1 RequestEntity (org.springframework.http.RequestEntity)1 HttpClientErrorException (org.springframework.web.client.HttpClientErrorException)1