Search in sources :

Example 6 with ResourceVariable

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);
}
Also used : Response(javax.ws.rs.core.Response) ResourceVariable(io.lumeer.api.model.ResourceVariable) Test(org.junit.Test)

Example 7 with ResourceVariable

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);
}
Also used : ResourceVariable(io.lumeer.api.model.ResourceVariable)

Example 8 with ResourceVariable

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);
}
Also used : ResourceVariableType(io.lumeer.api.model.ResourceVariableType) ResourceVariable(io.lumeer.api.model.ResourceVariable) ResourceType(io.lumeer.api.model.ResourceType) Document(org.bson.Document)

Example 9 with ResourceVariable

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);
    }
}
Also used : TemplateNotAvailableException(io.lumeer.core.exception.TemplateNotAvailableException) ResourceVariable(io.lumeer.api.model.ResourceVariable) JSONObject(org.json.simple.JSONObject) JSONArray(org.json.simple.JSONArray) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Example 10 with ResourceVariable

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);
        }
    }
}
Also used : AppId(io.lumeer.api.model.AppId) Sequence(io.lumeer.api.model.Sequence) RemoveSequence(io.lumeer.engine.api.event.RemoveSequence) RemoveResource(io.lumeer.engine.api.event.RemoveResource) OrganizationUserEvent(io.lumeer.engine.api.event.OrganizationUserEvent) CollectionDao(io.lumeer.storage.api.dao.CollectionDao) Resource(io.lumeer.api.model.common.Resource) ResourceVariableAdapter(io.lumeer.core.adapter.ResourceVariableAdapter) CreateResourceVariable(io.lumeer.engine.api.event.CreateResourceVariable) ResourceCommentDao(io.lumeer.storage.api.dao.ResourceCommentDao) RequestDataKeeper(io.lumeer.core.auth.RequestDataKeeper) ConstraintManager(io.lumeer.core.constraint.ConstraintManager) CreateOrUpdateSequence(io.lumeer.engine.api.event.CreateOrUpdateSequence) CreateOrUpdatePayment(io.lumeer.engine.api.event.CreateOrUpdatePayment) UpdateResourceVariable(io.lumeer.engine.api.event.UpdateResourceVariable) CreateDocument(io.lumeer.engine.api.event.CreateDocument) Set(java.util.Set) LinkInstance(io.lumeer.api.model.LinkInstance) CreateOrUpdateUserNotification(io.lumeer.engine.api.event.CreateOrUpdateUserNotification) LinkType(io.lumeer.api.model.LinkType) Group(io.lumeer.api.model.Group) CreateOrUpdateUser(io.lumeer.engine.api.event.CreateOrUpdateUser) PusherClient(io.lumeer.core.util.PusherClient) RemoveUserNotification(io.lumeer.engine.api.event.RemoveUserNotification) FavoriteItemDao(io.lumeer.storage.api.dao.FavoriteItemDao) ViewAdapter(io.lumeer.core.adapter.ViewAdapter) Utils(io.lumeer.core.util.Utils) CreateDocumentsAndLinks(io.lumeer.engine.api.event.CreateDocumentsAndLinks) UserDao(io.lumeer.storage.api.dao.UserDao) DocumentAdapter(io.lumeer.core.adapter.DocumentAdapter) CreateOrUpdateGroup(io.lumeer.engine.api.event.CreateOrUpdateGroup) RemoveLinkType(io.lumeer.engine.api.event.RemoveLinkType) OrganizationDao(io.lumeer.storage.api.dao.OrganizationDao) FavoriteItem(io.lumeer.engine.api.event.FavoriteItem) ViewDao(io.lumeer.storage.api.dao.ViewDao) RemoveResourceComment(io.lumeer.engine.api.event.RemoveResourceComment) RemoveUser(io.lumeer.engine.api.event.RemoveUser) Permissions(io.lumeer.api.model.Permissions) ResourceAdapter(io.lumeer.core.adapter.ResourceAdapter) ResourceComment(io.lumeer.api.model.ResourceComment) LinkTypeAdapter(io.lumeer.core.adapter.LinkTypeAdapter) DocumentUtils(io.lumeer.core.util.DocumentUtils) RemoveSelectionList(io.lumeer.engine.api.event.RemoveSelectionList) Project(io.lumeer.api.model.Project) LinkInstanceDao(io.lumeer.storage.api.dao.LinkInstanceDao) PermissionAdapter(io.lumeer.core.adapter.PermissionAdapter) CreateSelectionList(io.lumeer.engine.api.event.CreateSelectionList) UpdateLinkType(io.lumeer.engine.api.event.UpdateLinkType) ResourceVariable(io.lumeer.api.model.ResourceVariable) ReloadResourceVariables(io.lumeer.engine.api.event.ReloadResourceVariables) UpdateDocument(io.lumeer.engine.api.event.UpdateDocument) TemplateCreated(io.lumeer.engine.api.event.TemplateCreated) SetDocumentLinks(io.lumeer.engine.api.event.SetDocumentLinks) ProjectDao(io.lumeer.storage.api.dao.ProjectDao) User(io.lumeer.api.model.User) LinkTypeDao(io.lumeer.storage.api.dao.LinkTypeDao) AddFavoriteItem(io.lumeer.engine.api.event.AddFavoriteItem) UpdateCompanyContact(io.lumeer.engine.api.event.UpdateCompanyContact) CreateLinkInstance(io.lumeer.engine.api.event.CreateLinkInstance) CreateResource(io.lumeer.engine.api.event.CreateResource) SelectionList(io.lumeer.api.model.SelectionList) RolesDifference(io.lumeer.api.model.RolesDifference) ResourceType(io.lumeer.api.model.ResourceType) UpdateDashboardData(io.lumeer.engine.api.event.UpdateDashboardData) UpdateResourceComment(io.lumeer.engine.api.event.UpdateResourceComment) Observes(javax.enterprise.event.Observes) ReloadSelectionLists(io.lumeer.engine.api.event.ReloadSelectionLists) RemoveFavoriteItem(io.lumeer.engine.api.event.RemoveFavoriteItem) CollectionAdapter(io.lumeer.core.adapter.CollectionAdapter) RemoveGroup(io.lumeer.engine.api.event.RemoveGroup) RoleType(io.lumeer.api.model.RoleType) View(io.lumeer.api.model.View) UpdateServiceLimits(io.lumeer.engine.api.event.UpdateServiceLimits) Document(io.lumeer.api.model.Document) RemoveDocument(io.lumeer.engine.api.event.RemoveDocument) ResourceVariableEvent(io.lumeer.engine.api.event.ResourceVariableEvent) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) UpdateCurrentUser(io.lumeer.engine.api.event.UpdateCurrentUser) CreateResourceComment(io.lumeer.engine.api.event.CreateResourceComment) DefaultConfigurationProducer(io.lumeer.core.facade.configuration.DefaultConfigurationProducer) List(java.util.List) PostConstruct(javax.annotation.PostConstruct) UpdateResource(io.lumeer.engine.api.event.UpdateResource) ReloadGroups(io.lumeer.engine.api.event.ReloadGroups) WithId(io.lumeer.api.model.common.WithId) LinkInstanceAdapter(io.lumeer.core.adapter.LinkInstanceAdapter) UserNotification(io.lumeer.api.model.UserNotification) CreateLinkType(io.lumeer.engine.api.event.CreateLinkType) SelectionListEvent(io.lumeer.engine.api.event.SelectionListEvent) UpdateDefaultViewConfig(io.lumeer.engine.api.event.UpdateDefaultViewConfig) Event(org.marvec.pusher.data.Event) DashboardData(io.lumeer.api.model.DashboardData) Level(java.util.logging.Level) HashSet(java.util.HashSet) Inject(javax.inject.Inject) DataDao(io.lumeer.storage.api.dao.DataDao) ReloadResourceContent(io.lumeer.engine.api.event.ReloadResourceContent) ReloadLinkTypeContent(io.lumeer.engine.api.event.ReloadLinkTypeContent) Organization(io.lumeer.api.model.Organization) RemoveResourceVariable(io.lumeer.engine.api.event.RemoveResourceVariable) DocumentDao(io.lumeer.storage.api.dao.DocumentDao) ImportResource(io.lumeer.engine.api.event.ImportResource) RemoveLinkInstance(io.lumeer.engine.api.event.RemoveLinkInstance) UpdateLinkInstance(io.lumeer.engine.api.event.UpdateLinkInstance) UpdateSelectionList(io.lumeer.engine.api.event.UpdateSelectionList) PusherAdapter(io.lumeer.core.adapter.PusherAdapter) RequestScoped(javax.enterprise.context.RequestScoped) Collections(java.util.Collections) Collection(io.lumeer.api.model.Collection) Project(io.lumeer.api.model.Project) CreateResourceVariable(io.lumeer.engine.api.event.CreateResourceVariable) UpdateResourceVariable(io.lumeer.engine.api.event.UpdateResourceVariable) ResourceVariable(io.lumeer.api.model.ResourceVariable) RemoveResourceVariable(io.lumeer.engine.api.event.RemoveResourceVariable) Organization(io.lumeer.api.model.Organization) OrganizationUserEvent(io.lumeer.engine.api.event.OrganizationUserEvent) ResourceVariableEvent(io.lumeer.engine.api.event.ResourceVariableEvent) SelectionListEvent(io.lumeer.engine.api.event.SelectionListEvent) Event(org.marvec.pusher.data.Event)

Aggregations

ResourceVariable (io.lumeer.api.model.ResourceVariable)15 Response (javax.ws.rs.core.Response)6 Test (org.junit.Test)6 ResourceType (io.lumeer.api.model.ResourceType)3 Entity (javax.ws.rs.client.Entity)3 AppId (io.lumeer.api.model.AppId)2 Collection (io.lumeer.api.model.Collection)2 DashboardData (io.lumeer.api.model.DashboardData)2 Document (io.lumeer.api.model.Document)2 Group (io.lumeer.api.model.Group)2 LinkInstance (io.lumeer.api.model.LinkInstance)2 LinkType (io.lumeer.api.model.LinkType)2 Organization (io.lumeer.api.model.Organization)2 Permissions (io.lumeer.api.model.Permissions)2 Project (io.lumeer.api.model.Project)2 ResourceComment (io.lumeer.api.model.ResourceComment)2 RoleType (io.lumeer.api.model.RoleType)2 RolesDifference (io.lumeer.api.model.RolesDifference)2 SelectionList (io.lumeer.api.model.SelectionList)2 Sequence (io.lumeer.api.model.Sequence)2