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