use of io.lumeer.api.model.ResourceVariable in project engine by Lumeer.
the class ResourceVariablesServiceIT method testDeleteVariable.
@Test
public void testDeleteVariable() {
final ResourceVariable variable = createVariable("key", "value", false);
Response response = client.target(variablesUrl).path(variable.getId()).request(MediaType.APPLICATION_JSON).buildDelete().invoke();
assertThat(response).isNotNull();
assertThat(response.getStatusInfo()).isEqualTo(Response.Status.OK);
assertThat(response.getLinks()).extracting(Link::getUri).containsOnly(UriBuilder.fromUri(variablesUrl).build());
assertThatThrownBy(() -> resourceVariableDao.getVariable(variable.getId())).isInstanceOf(StorageException.class);
}
use of io.lumeer.api.model.ResourceVariable in project engine by Lumeer.
the class ResourceVariableFacade method getVariable.
public ResourceVariable getVariable(String id) {
ResourceVariable currentVariable = resourceVariableDao.getVariable(id);
checkPermissions(currentVariable, RoleType.TechConfig);
return mapVariable(currentVariable);
}
use of io.lumeer.api.model.ResourceVariable in project engine by Lumeer.
the class ResourceVariableCodec method decode.
@Override
public ResourceVariable decode(final BsonReader bsonReader, final DecoderContext decoderContext) {
Document bson = documentCodec.decode(bsonReader, decoderContext);
String id = bson.getObjectId(ID).toHexString();
String key = bson.getString(KEY);
Object value = bson.getString(VALUE);
String resourceId = bson.getString(RESOURCE_ID);
ResourceType resourceType = ResourceType.fromString(bson.getString(RESOURCE_TYPE));
ResourceVariableType type = ResourceVariableType.fromString(bson.getString(TYPE));
String organizationId = bson.getString(ORGANIZATION_ID);
String projectId = bson.getString(PROJECT_ID);
Boolean secure = bson.getBoolean(SECURE);
return new ResourceVariable(id, resourceId, resourceType, key, value, type, secure, organizationId, projectId);
}
use of io.lumeer.api.model.ResourceVariable in project engine by Lumeer.
the class ResourceVariableCreator method createComments.
private void createComments() {
final JSONArray variables = (JSONArray) templateParser.template.get("variables");
List<ResourceVariable> currentVariables = resourceVariableFacade.getInProject(projectId);
Set<String> currentKeys = currentVariables.stream().map(ResourceVariable::getKey).collect(Collectors.toSet());
;
if (variables != null) {
final List<ResourceVariable> result = new ArrayList<>();
variables.forEach(variableObj -> {
try {
var variableJson = (JSONObject) variableObj;
var resourceVariable = mapper.readValue(variableJson.toJSONString(), ResourceVariable.class);
resourceVariable.setId(null);
if (currentKeys.contains(resourceVariable.getKey()) || resourceVariable.getResourceType() == ResourceType.ORGANIZATION) {
return;
}
if (resourceVariable.getResourceType() == ResourceType.PROJECT) {
resourceVariable.setOrganizationId(organizationId);
resourceVariable.setProjectId(null);
resourceVariable.setResourceId(projectId);
} else {
resourceVariable.setOrganizationId(organizationId);
resourceVariable.setProjectId(projectId);
var translatedResourceId = templateParser.translateString(resourceVariable.getResourceId(), constraintManager);
resourceVariable.setResourceId(translatedResourceId != null ? translatedResourceId.toString() : null);
}
currentKeys.add(resourceVariable.getKey());
result.add(resourceVariable);
} catch (IOException e) {
throw new TemplateNotAvailableException(e);
}
});
resourceVariableFacade.storeResourceVariables(result, organizationId, projectId);
}
}
use of io.lumeer.api.model.ResourceVariable in project engine by Lumeer.
the class PusherFacade method createOrUpdateResourceVariableNotification.
public void createOrUpdateResourceVariableNotification(final ResourceVariableEvent resourceVariableEvent, final String suffix) {
if (isEnabled()) {
try {
ResourceVariable resourceVariable = resourceVariableAdapter.mapVariable(resourceVariableEvent.getVariable());
Organization organization = organizationDao.getOrganizationById(resourceVariable.getOrganizationId());
Set<String> users;
ObjectWithParent object;
ResourceId backup;
if (resourceVariable.getResourceType() == ResourceType.ORGANIZATION) {
object = new ObjectWithParent(getAppId(), resourceVariable, organization.getId());
backup = new ResourceId(getAppId(), resourceVariable.getId(), organization.getId());
users = permissionAdapter.getOrganizationUsersByRole(organization, RoleType.TechConfig);
} else {
Project project = projectDao.getProjectById(resourceVariable.getProjectId());
object = new ObjectWithParent(getAppId(), resourceVariable, organization.getId(), project.getId());
backup = new ResourceId(getAppId(), resourceVariable.getId(), organization.getId(), project.getId());
users = permissionAdapter.getProjectUsersByRole(organization, project, RoleType.TechConfig);
}
List<Event> events = users.stream().map(userId -> pusherAdapter.createEventForObjectWithParent(object, backup, suffix, userId)).collect(Collectors.toList());
sendNotificationsBatch(events);
} catch (Exception e) {
log.log(Level.WARNING, "Unable to send push notification: ", e);
}
}
}
Aggregations