Skip to content

Commit

Permalink
Merge pull request #2922 from ingef/release
Browse files Browse the repository at this point in the history
Merge Release
  • Loading branch information
thoniTUB authored Feb 7, 2023
2 parents 716c326 + 96fc2b0 commit fb7eb9c
Show file tree
Hide file tree
Showing 101 changed files with 2,894 additions and 1,034 deletions.
2 changes: 1 addition & 1 deletion backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@
<dependency>
<groupId>com.auth0</groupId>
<artifactId>java-jwt</artifactId>
<version>3.18.1</version>
<version>4.2.2</version>
</dependency>
<dependency>
<groupId>io.dropwizard</groupId>
Expand Down
2 changes: 2 additions & 0 deletions backend/src/main/java/com/bakdata/conquery/apiv1/IdLabel.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.bakdata.conquery.models.identifiable.ids.Id;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.ToString;

/**
* Container class for the frontend to provide a tuple of id and a corresponding label.
Expand All @@ -14,6 +15,7 @@
*/
@Getter
@RequiredArgsConstructor
@ToString
public class IdLabel<I extends Id<?>> implements Comparable<IdLabel<I>> {
@NotEmpty
private final I id;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.bakdata.conquery.apiv1.frontend;

import java.util.Collection;

import com.bakdata.conquery.io.jackson.serializer.NsIdRef;
import com.bakdata.conquery.models.datasets.concepts.Concept;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;

@Data
public class FrontendPreviewConfig {
@Data
public static class Labelled {
private final String name;
private final String label;
}

private final Collection<Labelled> all;
@JsonProperty("default")
private final Collection<Labelled> defaultConnectors;

@NsIdRef
private final Concept<?> searchConcept;
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void resolve(final QueryResolveContext context) {
}
final QueryResolveContext resolvedContext = context.withDateAggregationMode(resolvedDateAggregationMode);

this.query = new ConceptQuery(root);
query = new ConceptQuery(root);
query.resolve(resolvedContext);

withSecondaryId = new HashSet<>();
Expand Down Expand Up @@ -143,16 +143,9 @@ private Column findSecondaryIdColumn(Table table) {

@Override
public List<ResultInfo> getResultInfos() {
List<ResultInfo> resultInfos = new ArrayList<>();

resultInfos.add(
new SimpleResultInfo(
secondaryId.getLabel(),
ResultType.StringT.INSTANCE,
secondaryId.getDescription(),
Set.of(new SemanticType.SecondaryIdT(getSecondaryId()))
)
);
final List<ResultInfo> resultInfos = new ArrayList<>();

resultInfos.add(new SimpleResultInfo(secondaryId.getLabel(), ResultType.StringT.INSTANCE, secondaryId.getDescription(), Set.of(new SemanticType.SecondaryIdT(getSecondaryId()))));

resultInfos.addAll(query.getResultInfos());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,23 @@ public void resolve(QueryResolveContext context) {
resultInfos = createResultInfos(secondaryIdPositions);
}

private Map<SecondaryIdDescription, Integer> calculateSecondaryIdPositions(AtomicInteger currentPosition) {
Map<SecondaryIdDescription, Integer> secondaryIdPositions = new HashMap<>();

// SecondaryIds are pulled to the front and grouped over all tables
tables.stream()
.flatMap(con -> con.getTables().stream())
.flatMap(table -> Arrays.stream(table.getConnector().getTable().getColumns()))
.map(Column::getSecondaryId)
.filter(Objects::nonNull)
.distinct()
.sorted(Comparator.comparing(SecondaryIdDescription::getLabel))
// Using for each and not a collector allows us to guarantee sorted insertion.
.forEach(secondaryId -> secondaryIdPositions.put(secondaryId, currentPosition.getAndIncrement()));

return secondaryIdPositions;
}

private static Map<Column, Integer> calculateColumnPositions(AtomicInteger currentPosition, List<CQConcept> tables, Map<SecondaryIdDescription, Integer> secondaryIdPositions) {
final Map<Column, Integer> positions = new HashMap<>();

Expand Down Expand Up @@ -184,23 +201,6 @@ private static Map<Column, Integer> calculateColumnPositions(AtomicInteger curre
return positions;
}

private Map<SecondaryIdDescription, Integer> calculateSecondaryIdPositions(AtomicInteger currentPosition) {
Map<SecondaryIdDescription, Integer> secondaryIdPositions = new HashMap<>();

// SecondaryIds are pulled to the front and grouped over all tables
tables.stream()
.flatMap(con -> con.getTables().stream())
.flatMap(table -> Arrays.stream(table.getConnector().getTable().getColumns()))
.map(Column::getSecondaryId)
.filter(Objects::nonNull)
.distinct()
.sorted(Comparator.comparing(SecondaryIdDescription::getLabel))
// Using for each and not a collector allows us to guarantee sorted insertion.
.forEach(secondaryId -> secondaryIdPositions.put(secondaryId, currentPosition.getAndIncrement()));

return secondaryIdPositions;
}

private List<ResultInfo> createResultInfos(Map<SecondaryIdDescription, Integer> secondaryIdPositions) {

final int size = positions.values().stream().mapToInt(i -> i).max().getAsInt() + 1;
Expand All @@ -210,6 +210,7 @@ private List<ResultInfo> createResultInfos(Map<SecondaryIdDescription, Integer>
infos[0] = ConqueryConstants.DATES_INFO_HISTORY;
infos[1] = ConqueryConstants.SOURCE_INFO;


for (Map.Entry<SecondaryIdDescription, Integer> e : secondaryIdPositions.entrySet()) {
final SecondaryIdDescription desc = e.getKey();
final Integer pos = e.getValue();
Expand Down Expand Up @@ -242,13 +243,18 @@ private List<ResultInfo> createResultInfos(Map<SecondaryIdDescription, Integer>

for (Map.Entry<Column, Integer> entry : positions.entrySet()) {

// 0 Position is date, already covered
final int position = entry.getValue();

final Column column = entry.getKey();

if(position == 0) {
continue;
}

// SecondaryIds and date columns are pulled to the front, thus already covered.
if (position == 0 || column.getSecondaryId() != null) {
if (column.getSecondaryId() != null) {
infos[secondaryIdPositions.get(column.getSecondaryId())].getSemantics()
.add(new SemanticType.ColumnT(column));
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ public interface ResultHeadersC10n {
@De("Quelle")
String source();

@En("event_duration")
@De("Anzahl relevanter Tage")
String eventDuration();


@En("event_date")
@De("Indexdatum")
String eventDate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.IOException;
import java.util.Currency;
import java.util.List;
import java.util.Locale;

import com.bakdata.conquery.io.cps.CPSTypeIdResolver;
import com.bakdata.conquery.io.jackson.serializer.CharArrayBufferDeserializer;
Expand All @@ -12,6 +13,8 @@
import com.bakdata.conquery.io.jackson.serializer.CurrencyUnitDeserializer;
import com.bakdata.conquery.io.jackson.serializer.CurrencyUnitSerializer;
import com.bakdata.conquery.io.jackson.serializer.IdKeyDeserializer;
import com.bakdata.conquery.io.jackson.serializer.LocaleDeserializer;
import com.bakdata.conquery.io.jackson.serializer.LocaleSerializer;
import com.bakdata.conquery.models.identifiable.ids.Id;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.deser.ValueInstantiator;
Expand Down Expand Up @@ -54,11 +57,14 @@ public Object createUsingDefault(DeserializationContext ctxt) throws IOException
.getSubclasses(Id.class.getName())
.loadClasses();

for(Class<?> type : idTypes) {
for (Class<?> type : idTypes) {
addKeyDeserializer(type, new IdKeyDeserializer<>());
}
addSerializer(new ConqueryDoubleSerializer());
addDeserializer(CharArrayBuffer.class, new CharArrayBufferDeserializer());
addSerializer(CharArrayBuffer.class, new CharArrayBufferSerializer());

addDeserializer(Locale.class, new LocaleDeserializer());
addSerializer(Locale.class, new LocaleSerializer());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.bakdata.conquery.io.jackson.serializer;

import java.io.IOException;
import java.util.Locale;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.exc.MismatchedInputException;
import org.apache.commons.lang3.StringUtils;

/**
* Parses a language tag as a locale using {@link Locale#forLanguageTag(String)}.
* Fails if the provided token is not a string token or the tag cannot be matched to a locale.
*/
public class LocaleDeserializer extends JsonDeserializer<Locale> {

public static final String ROOT_LOCALE_TAG = Locale.ROOT.toLanguageTag();

@Override
public Locale deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
final JsonToken jsonToken = p.currentToken();
if (jsonToken != JsonToken.VALUE_STRING) {
throw MismatchedInputException.from(p, Locale.class, "Expected a string token but found: " + jsonToken);
}

final String languageTag = p.getText();
final Locale locale = Locale.forLanguageTag(languageTag);

if (StringUtils.isNotBlank(languageTag) && !languageTag.equals(ROOT_LOCALE_TAG) && locale == Locale.ROOT) {
// When Locale#forLanguageTag does not recognize the tag it defaults to Locale.ROOT
// This should only be intended if the tag was blank or "und" (undefined ~= Locale.ROOT.toLanguageTag())
throw MismatchedInputException.from(p, Locale.class, "Unable to map language tag '" + languageTag + "' to locale");
}

return locale;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.bakdata.conquery.io.jackson.serializer;

import java.io.IOException;
import java.util.Locale;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

/**
* Uses the language tag provided by {@link Locale#toLanguageTag()} to serialize a locale as a string token.
* Without this serializer Jackson would write out {@link Locale#GERMANY} as {@code \"de_DE\"}.
* This serializer writes the locale as {@code de-DE}.
*/
public class LocaleSerializer extends JsonSerializer<Locale> {
@Override
public void serialize(Locale value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
gen.writeString(value.toLanguageTag());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Locale;

import javax.ws.rs.BadRequestException;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.StreamingOutput;

import com.bakdata.conquery.models.auth.entities.Subject;
import com.bakdata.conquery.models.auth.permissions.Ability;
Expand All @@ -18,15 +20,6 @@
import com.google.common.base.Strings;
import lombok.extern.slf4j.Slf4j;

import javax.ws.rs.BadRequestException;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.StreamingOutput;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Locale;

@Slf4j
public class ResultUtil {

Expand All @@ -42,8 +35,7 @@ String getHeaderValue() {
}


public static Response makeResponseWithFileName(StreamingOutput out, String label, String fileExtension, MediaType mediaType, ContentDispositionOption disposition) {
Response.ResponseBuilder response = Response.ok(out);
public static Response makeResponseWithFileName(Response.ResponseBuilder response, String label, String fileExtension, MediaType mediaType, ContentDispositionOption disposition) {
response.header(HttpHeaders.CONTENT_TYPE, mediaType);
if (!(Strings.isNullOrEmpty(label) || label.isBlank())) {
// Set filename from label if the label was set, otherwise the browser will name the file according to the request path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public static <E extends ManagedExecution<?> & SingleTableResult> Response getAr
}
};

return makeResponseWithFileName(out, exec.getLabelWithoutAutoLabelSuffix(), fileExtension, mediaType, ResultUtil.ContentDispositionOption.ATTACHMENT);
return makeResponseWithFileName(Response.ok(out), exec.getLabelWithoutAutoLabelSuffix(), fileExtension, mediaType, ResultUtil.ContentDispositionOption.ATTACHMENT);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public <E extends ManagedExecution<?> & SingleTableResult> Response createResult
}
};

return makeResponseWithFileName(out, exec.getLabelWithoutAutoLabelSuffix(), "csv", new MediaType("text", "csv", charset.toString()), ResultUtil.ContentDispositionOption.ATTACHMENT);
return makeResponseWithFileName(Response.ok(out), exec.getLabelWithoutAutoLabelSuffix(), "csv", new MediaType("text", "csv", charset.toString()), ResultUtil.ContentDispositionOption.ATTACHMENT);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public <E extends ManagedExecution<?> & SingleTableResult> Response createResult
log.trace("FINISHED downloading {}", exec.getId());
};

return makeResponseWithFileName(out, exec.getLabelWithoutAutoLabelSuffix(), "xlsx", MEDIA_TYPE, ResultUtil.ContentDispositionOption.ATTACHMENT);
return makeResponseWithFileName(Response.ok(out), exec.getLabelWithoutAutoLabelSuffix(), "xlsx", MEDIA_TYPE, ResultUtil.ContentDispositionOption.ATTACHMENT);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,6 @@ public Response createResultFile(Subject subject, ManagedExecution<?> exec, bool
};


return makeResponseWithFileName(out, exec.getLabelWithoutAutoLabelSuffix(), FILE_EXTENTION_PARQUET, PARQUET_MEDIA_TYPE, ResultUtil.ContentDispositionOption.ATTACHMENT);
return makeResponseWithFileName(Response.ok(out), exec.getLabelWithoutAutoLabelSuffix(), FILE_EXTENTION_PARQUET, PARQUET_MEDIA_TYPE, ResultUtil.ContentDispositionOption.ATTACHMENT);
}
}
Loading

0 comments on commit fb7eb9c

Please sign in to comment.