Search in sources :

Example 1 with Form

use of com.bakdata.conquery.apiv1.forms.Form in project conquery by bakdata.

the class FormConfigTest method addConfigWithoutTranslation.

@Test
public void addConfigWithoutTranslation() {
    user.addPermission(dataset.createPermission(Ability.READ.asSet()));
    ObjectMapper mapper = FormConfigProcessor.getMAPPER();
    FormConfigAPI formConfig = FormConfigAPI.builder().formType(form.getFormType()).values(mapper.valueToTree(form)).build();
    processor.addConfig(user, dataset, formConfig);
    assertThat(storage.getAllFormConfigs()).containsExactly(FormConfigAPI.intern(formConfig, user, dataset));
}
Also used : FormConfigAPI(com.bakdata.conquery.apiv1.forms.FormConfigAPI) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.jupiter.api.Test)

Example 2 with Form

use of com.bakdata.conquery.apiv1.forms.Form in project conquery by bakdata.

the class DateContext method generateAbsoluteContexts.

/**
 * Generates a date context list of sub date ranges from the given dateRangeMask.
 * The generation of the contexts happens for each resolution with their mapped alignment.
 * The returned list is primarily sorted in the order of the given resolutions and secondarily by the temporal
 * succession of the contexts, e.g.: with resolutions YEARS, QUARTERS given the list would first contain the
 * ascending year ranges and than the quarter ranges. The alignment references always the lower bound of the
 * dateRangeMask.
 * @param dateRangeMask The mask in which the contexts are generated
 * @param resolutionAndAlignment The resolutions to produce and their alignment
 * @return A sorted list of all generated contexts
 */
public static List<DateContext> generateAbsoluteContexts(CDateRange dateRangeMask, List<ExportForm.ResolutionAndAlignment> resolutionAndAlignment) {
    List<DateContext> dcList = new ArrayList<>();
    for (ExportForm.ResolutionAndAlignment mode : resolutionAndAlignment) {
        Function<CDateRange, List<CDateRange>> divider = getDateRangeSubdivider(AlignmentReference.START, mode.getResolution(), mode.getAlignment());
        // Start counting index form 0 for every subdivision mode
        int index = 0;
        for (CDateRange quarterInMask : divider.apply(dateRangeMask)) {
            index++;
            DateContext dc = new DateContext(quarterInMask, FeatureGroup.OUTCOME, // For now there is no index for complete
            mode.getResolution().equals(Resolution.COMPLETE) ? null : index, null, mode.getResolution());
            dcList.add(dc);
        }
    }
    return dcList;
}
Also used : CDateRange(com.bakdata.conquery.models.common.daterange.CDateRange) ExportForm(com.bakdata.conquery.apiv1.forms.export_form.ExportForm)

Example 3 with Form

use of com.bakdata.conquery.apiv1.forms.Form in project conquery by bakdata.

the class ExecuteForm method react.

@Override
public void react(Worker worker) throws Exception {
    log.info("Started Form {}", formId);
    // Execution might have been cancelled before so we uncancel it here.
    final QueryExecutor queryExecutor = worker.getQueryExecutor();
    queryExecutor.unsetQueryCancelled(formId);
    // Execute all plans.
    for (Entry<ManagedExecutionId, Query> entry : queries.entrySet()) {
        final Query query = entry.getValue();
        ShardResult result = createResult(worker, entry.getKey());
        // Before we start the query, we create it once to test if it will succeed before creating it multiple times for evaluation per core.
        try {
            query.createQueryPlan(new QueryPlanContext(worker));
        } catch (Exception e) {
            ConqueryError err = asConqueryError(e);
            log.warn("Failed to create query plans for {}.", formId, err);
            queryExecutor.sendFailureToManagerNode(result, err);
            return;
        }
        final QueryExecutionContext subQueryContext = new QueryExecutionContext(formId, queryExecutor, worker.getStorage(), worker.getBucketManager());
        if (!queryExecutor.execute(query, subQueryContext, result)) {
            return;
        }
    }
}
Also used : ConqueryError.asConqueryError(com.bakdata.conquery.models.error.ConqueryError.asConqueryError) ConqueryError(com.bakdata.conquery.models.error.ConqueryError) Query(com.bakdata.conquery.apiv1.query.Query) QueryExecutionContext(com.bakdata.conquery.models.query.QueryExecutionContext) QueryExecutor(com.bakdata.conquery.models.query.QueryExecutor) ManagedExecutionId(com.bakdata.conquery.models.identifiable.ids.specific.ManagedExecutionId) FormShardResult(com.bakdata.conquery.models.query.results.FormShardResult) ShardResult(com.bakdata.conquery.models.query.results.ShardResult) QueryPlanContext(com.bakdata.conquery.models.query.QueryPlanContext)

Example 4 with Form

use of com.bakdata.conquery.apiv1.forms.Form in project conquery by bakdata.

the class SerializationTests method formConfig.

@Test
public void formConfig() throws JSONException, IOException {
    final CentralRegistry registry = new CentralRegistry();
    final Dataset dataset = new Dataset("test-dataset");
    registry.register(dataset);
    ExportForm form = new ExportForm();
    AbsoluteMode mode = new AbsoluteMode();
    form.setTimeMode(mode);
    mode.setForm(form);
    mode.setFeatures(List.of(new CQConcept()));
    ObjectMapper mapper = FormConfigProcessor.getMAPPER();
    JsonNode values = mapper.valueToTree(form);
    FormConfig formConfig = new FormConfig(form.getClass().getAnnotation(CPSType.class).id(), values);
    formConfig.setDataset(dataset);
    SerializationTestUtil.forType(FormConfig.class).registry(registry).test(formConfig);
}
Also used : FormConfig(com.bakdata.conquery.models.forms.configs.FormConfig) AbsoluteMode(com.bakdata.conquery.apiv1.forms.export_form.AbsoluteMode) Dataset(com.bakdata.conquery.models.datasets.Dataset) CQConcept(com.bakdata.conquery.apiv1.query.concept.specific.CQConcept) JsonNode(com.fasterxml.jackson.databind.JsonNode) CentralRegistry(com.bakdata.conquery.models.identifiable.CentralRegistry) ExportForm(com.bakdata.conquery.apiv1.forms.export_form.ExportForm) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.jupiter.api.Test) IdMapSerialisationTest(com.bakdata.conquery.models.identifiable.IdMapSerialisationTest)

Example 5 with Form

use of com.bakdata.conquery.apiv1.forms.Form in project conquery by bakdata.

the class AuthorizationController method flatCopyUser.

/**
 * Creates a copy of an existing user. The copied user has the same effective permissions as the original user
 * at the time of copying, but these are flatted. This means that the original user might hold certain permissions
 * through inheritance from roles or groups, the copy will hold the permissions directly.
 * @param originUser The user to make a flat copy of
 * @param namePrefix The prefix for the id of the new copied user
 * @return A flat copy of the referenced user
 */
public static User flatCopyUser(@NonNull User originUser, String namePrefix, @NonNull MetaStorage storage) {
    final UserId originUserId = originUser.getId();
    if (Strings.isNullOrEmpty(namePrefix)) {
        throw new IllegalArgumentException("There must be a prefix");
    }
    // Find a new user id that is not used yet
    String name = null;
    do {
        name = namePrefix + UUID.randomUUID() + originUserId.getName();
    } while (storage.getUser(new UserId(name)) != null);
    // Retrieve original user and its effective permissions
    // Copy inherited permissions
    Set<ConqueryPermission> copiedPermission = new HashSet<>();
    copiedPermission.addAll(originUser.getEffectivePermissions());
    // Give read permission to all executions the original user owned
    copiedPermission.addAll(storage.getAllExecutions().stream().filter(originUser::isOwner).map(exc -> exc.createPermission(Ability.READ.asSet())).collect(Collectors.toSet()));
    // Give read permission to all form configs the original user owned
    copiedPermission.addAll(storage.getAllFormConfigs().stream().filter(originUser::isOwner).map(conf -> conf.createPermission(Ability.READ.asSet())).collect(Collectors.toSet()));
    // Create copied user
    User copy = new User(name, originUser.getLabel(), storage);
    storage.addUser(copy);
    copy.updatePermissions(copiedPermission);
    return copy;
}
Also used : ConqueryPermission(com.bakdata.conquery.models.auth.permissions.ConqueryPermission) ProtoUser(com.bakdata.conquery.apiv1.auth.ProtoUser) User(com.bakdata.conquery.models.auth.entities.User) UserId(com.bakdata.conquery.models.identifiable.ids.specific.UserId) HashSet(java.util.HashSet)

Aggregations

ExportForm (com.bakdata.conquery.apiv1.forms.export_form.ExportForm)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 Test (org.junit.jupiter.api.Test)4 FormConfigAPI (com.bakdata.conquery.apiv1.forms.FormConfigAPI)3 CQConcept (com.bakdata.conquery.apiv1.query.concept.specific.CQConcept)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 Form (com.bakdata.conquery.apiv1.forms.Form)2 AbsoluteMode (com.bakdata.conquery.apiv1.forms.export_form.AbsoluteMode)2 User (com.bakdata.conquery.models.auth.entities.User)2 FormConfig (com.bakdata.conquery.models.forms.configs.FormConfig)2 FormConfigId (com.bakdata.conquery.models.identifiable.ids.specific.FormConfigId)2 TextNode (com.fasterxml.jackson.databind.node.TextNode)2 ProtoUser (com.bakdata.conquery.apiv1.auth.ProtoUser)1 RelativeMode (com.bakdata.conquery.apiv1.forms.export_form.RelativeMode)1 Query (com.bakdata.conquery.apiv1.query.Query)1 CPSType (com.bakdata.conquery.io.cps.CPSType)1 Group (com.bakdata.conquery.models.auth.entities.Group)1 ConqueryPermission (com.bakdata.conquery.models.auth.permissions.ConqueryPermission)1 CDateRange (com.bakdata.conquery.models.common.daterange.CDateRange)1 Dataset (com.bakdata.conquery.models.datasets.Dataset)1