Search in sources :

Example 1 with DictionaryEntity

use of io.gravitee.rest.api.model.configuration.dictionary.DictionaryEntity in project gravitee-management-rest-api by gravitee-io.

the class DictionaryService method onEvent.

@Override
public void onEvent(Event<DictionaryEvent, DictionaryEntity> event) {
    final DictionaryEntity dictionary = event.content();
    switch(event.type()) {
        case START:
            startDynamicDictionary(dictionary);
            break;
        case STOP:
            stopDynamicDictionary(dictionary);
            break;
        case RESTART:
            stopDynamicDictionary(dictionary);
            startDynamicDictionary(dictionary);
            break;
    }
}
Also used : DictionaryEntity(io.gravitee.rest.api.model.configuration.dictionary.DictionaryEntity)

Example 2 with DictionaryEntity

use of io.gravitee.rest.api.model.configuration.dictionary.DictionaryEntity in project gravitee-management-rest-api by gravitee-io.

the class DictionaryManagerTest method shouldStart.

@Test
public void shouldStart() {
    final DictionaryEntity dictionary = new DictionaryEntity();
    dictionary.setId(DICTIONARY_ID);
    when(dictionaryService.findById(DICTIONARY_ID)).thenReturn(dictionary);
    cut.start(DICTIONARY_ID);
    verify(eventManager, times(1)).publishEvent(eq(DictionaryEvent.START), eq(dictionary));
}
Also used : DictionaryEntity(io.gravitee.rest.api.model.configuration.dictionary.DictionaryEntity) Test(org.junit.Test)

Example 3 with DictionaryEntity

use of io.gravitee.rest.api.model.configuration.dictionary.DictionaryEntity in project gravitee-management-rest-api by gravitee-io.

the class DictionaryManager method stop.

/**
 * Stop the dictionary.
 * @param dictionaryId the id of the dictionary.
 */
public void stop(String dictionaryId) {
    try {
        DictionaryEntity dictionary = new DictionaryEntity();
        dictionary.setId(dictionaryId);
        eventManager.publishEvent(DictionaryEvent.STOP, dictionary);
        dictionaries.remove(dictionaryId);
    } catch (Exception e) {
        logger.error("Error occurred when trying to stop the dictionary [{}].", dictionaryId, e);
    }
}
Also used : DictionaryEntity(io.gravitee.rest.api.model.configuration.dictionary.DictionaryEntity)

Example 4 with DictionaryEntity

use of io.gravitee.rest.api.model.configuration.dictionary.DictionaryEntity in project gravitee-management-rest-api by gravitee-io.

the class DictionaryManagerTest method shouldRestartProviderConfigChanged.

@Test
public void shouldRestartProviderConfigChanged() {
    final DictionaryProviderEntity provider = new DictionaryProviderEntity();
    provider.setConfiguration(JsonNodeFactory.instance.nullNode());
    final DictionaryTriggerEntity trigger = new DictionaryTriggerEntity();
    trigger.setRate(1);
    trigger.setUnit(TimeUnit.SECONDS);
    final DictionaryEntity dictionary = new DictionaryEntity();
    dictionary.setUpdatedAt(new Date());
    dictionary.setProvider(provider);
    dictionary.setId(DICTIONARY_ID);
    dictionary.setTrigger(trigger);
    final DictionaryProviderEntity providerUpdated = new DictionaryProviderEntity();
    providerUpdated.setConfiguration(JsonNodeFactory.instance.arrayNode());
    final DictionaryEntity dictionaryUpdated = new DictionaryEntity();
    dictionaryUpdated.setUpdatedAt(new Date(ZonedDateTime.now().plusSeconds(60).toInstant().toEpochMilli()));
    dictionaryUpdated.setProvider(providerUpdated);
    dictionaryUpdated.setId(DICTIONARY_ID);
    dictionaryUpdated.setTrigger(trigger);
    when(dictionaryService.findById(DICTIONARY_ID)).thenReturn(dictionary).thenReturn(dictionaryUpdated);
    cut.start(DICTIONARY_ID);
    cut.start(DICTIONARY_ID);
    verify(eventManager, times(1)).publishEvent(eq(DictionaryEvent.START), eq(dictionary));
    verify(eventManager, times(1)).publishEvent(eq(DictionaryEvent.RESTART), eq(dictionary));
    verifyNoMoreInteractions(eventManager);
}
Also used : DictionaryEntity(io.gravitee.rest.api.model.configuration.dictionary.DictionaryEntity) DictionaryTriggerEntity(io.gravitee.rest.api.model.configuration.dictionary.DictionaryTriggerEntity) DictionaryProviderEntity(io.gravitee.rest.api.model.configuration.dictionary.DictionaryProviderEntity) Date(java.util.Date) Test(org.junit.Test)

Example 5 with DictionaryEntity

use of io.gravitee.rest.api.model.configuration.dictionary.DictionaryEntity in project gravitee-management-rest-api by gravitee-io.

the class DictionaryResource method getDictionary.

@GET
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Get a dictionary", notes = "User must have the DICTIONARY[READ] permission to use this service")
@ApiResponses({ @ApiResponse(code = 200, message = "A dictionary"), @ApiResponse(code = 500, message = "Internal server error") })
@Permissions(@Permission(value = RolePermission.ENVIRONMENT_DICTIONARY, acls = RolePermissionAction.READ))
public DictionaryEntity getDictionary(@PathParam("dictionary") String dictionary) {
    DictionaryEntity dictionaryEntity = dictionaryService.findById(dictionary);
    // remove provider informations for readonlyUsers
    boolean notReadOnly = hasPermission(RolePermission.ENVIRONMENT_DICTIONARY, RolePermissionAction.CREATE, RolePermissionAction.UPDATE, RolePermissionAction.DELETE);
    if (!notReadOnly) {
        dictionaryEntity.setProvider(null);
        dictionaryEntity.setTrigger(null);
    }
    return dictionaryEntity;
}
Also used : UpdateDictionaryEntity(io.gravitee.rest.api.model.configuration.dictionary.UpdateDictionaryEntity) DictionaryEntity(io.gravitee.rest.api.model.configuration.dictionary.DictionaryEntity) Permissions(io.gravitee.rest.api.management.rest.security.Permissions)

Aggregations

DictionaryEntity (io.gravitee.rest.api.model.configuration.dictionary.DictionaryEntity)11 Test (org.junit.Test)6 DictionaryProviderEntity (io.gravitee.rest.api.model.configuration.dictionary.DictionaryProviderEntity)3 Date (java.util.Date)3 Permissions (io.gravitee.rest.api.management.rest.security.Permissions)2 DictionaryTriggerEntity (io.gravitee.rest.api.model.configuration.dictionary.DictionaryTriggerEntity)2 NewDictionaryEntity (io.gravitee.rest.api.model.configuration.dictionary.NewDictionaryEntity)2 UpdateDictionaryEntity (io.gravitee.rest.api.model.configuration.dictionary.UpdateDictionaryEntity)2 Response (javax.ws.rs.core.Response)2