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;
}
}
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));
}
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);
}
}
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);
}
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;
}
Aggregations