use of com.linkedin.data.template.StringMap in project incubator-gobblin by apache.
the class DatabaseJobHistoryStoreV101 method addPropertiesToTasks.
private void addPropertiesToTasks(Connection connection, JobExecutionQuery query, Filter tableFilter, Map<String, Map<String, TaskExecutionInfo>> taskExecutionInfos) throws SQLException {
if (taskExecutionInfos.size() > 0) {
Set<String> propertyKeys = null;
if (query.hasTaskProperties()) {
propertyKeys = Sets.newHashSet(Iterables.filter(Arrays.asList(query.getTaskProperties().split(",")), new Predicate<String>() {
@Override
public boolean apply(String input) {
return !Strings.isNullOrEmpty(input);
}
}));
}
if (propertyKeys == null || propertyKeys.size() > 0) {
String template = String.format(TASK_PROPERTY_QUERY_STATEMENT_TEMPLATE, getInPredicate(taskExecutionInfos.size()));
if (propertyKeys != null && propertyKeys.size() > 0) {
template += String.format("AND property_key IN (%s)", getInPredicate(propertyKeys.size()));
}
if (tableFilter.isPresent()) {
template += " AND t." + tableFilter;
}
int index = 1;
try (PreparedStatement taskPropertiesQueryStatement = connection.prepareStatement(template)) {
for (String jobId : taskExecutionInfos.keySet()) {
taskPropertiesQueryStatement.setString(index++, jobId);
}
if (propertyKeys != null && propertyKeys.size() > 0) {
for (String propertyKey : propertyKeys) {
taskPropertiesQueryStatement.setString(index++, propertyKey);
}
}
if (tableFilter.isPresent()) {
tableFilter.addParameters(taskPropertiesQueryStatement, index);
}
try (ResultSet taskPropertiesRs = taskPropertiesQueryStatement.executeQuery()) {
while (taskPropertiesRs.next()) {
String jobId = taskPropertiesRs.getString("job_id");
String taskId = taskPropertiesRs.getString("task_id");
TaskExecutionInfo taskExecutionInfo = taskExecutionInfos.get(jobId).get(taskId);
StringMap taskProperties = taskExecutionInfo.getTaskProperties(GetMode.NULL);
if (taskProperties == null) {
taskProperties = new StringMap();
taskExecutionInfo.setTaskProperties(taskProperties);
}
Map.Entry<String, String> property = resultSetToProperty(taskPropertiesRs);
if (propertyKeys == null || propertyKeys.contains(property.getKey())) {
taskProperties.put(property.getKey(), property.getValue());
}
}
}
}
}
}
}
use of com.linkedin.data.template.StringMap in project rest.li by linkedin.
the class MultiplexerTestBase method fakeIndividualRequest.
protected static IndividualRequest fakeIndividualRequest(String url, Map<String, IndividualRequest> dependentCalls) {
IndividualRequest request = new IndividualRequest();
request.setMethod(HttpMethod.GET.name());
request.setHeaders(new StringMap(HEADERS));
request.setRelativeUrl(url);
request.setDependentRequests(new IndividualRequestMap(dependentCalls));
return request;
}
use of com.linkedin.data.template.StringMap in project rest.li by linkedin.
the class MultiplexedRequestBuilder method toIndividualRequest.
private static IndividualRequest toIndividualRequest(Request<?> request, IndividualRequestMap dependantRequests) throws RestLiEncodingException {
// TODO: Hardcoding RESTLI_PROTOCOL_2_0_0 for now. We need to refactor this code later to get protocol version using the mechanism similar to
// RestClient.getProtocolVersionForService()
ProtocolVersion protocolVersion = AllProtocolVersions.RESTLI_PROTOCOL_2_0_0.getProtocolVersion();
String relativeUrl = getRelativeUrl(request, protocolVersion);
IndividualRequest individualRequest = new IndividualRequest();
individualRequest.setRelativeUrl(relativeUrl);
individualRequest.setMethod(request.getMethod().getHttpMethod().name());
individualRequest.setHeaders(new StringMap(request.getHeaders()));
List<HttpCookie> cookies = request.getCookies();
if (cookies != null && !cookies.isEmpty()) {
throw new IllegalArgumentException(String.format("Cookies for individual request '%s' MUST be added at the envelope request level", relativeUrl));
}
individualRequest.setBody(getBody(request, protocolVersion), SetMode.IGNORE_NULL);
individualRequest.setDependentRequests(dependantRequests);
return individualRequest;
}
use of com.linkedin.data.template.StringMap in project rest.li by linkedin.
the class TestRestLiMethodInvocation method testInvoke_testComplexParameters.
@Test
public void testInvoke_testComplexParameters() throws Exception {
ResourceModel accountsResourceModel = buildResourceModel(TwitterAccountsResource.class);
ResourceMethodDescriptor methodDescriptor;
TwitterAccountsResource accountsResource;
// #1 no defaults provided
methodDescriptor = accountsResourceModel.findActionMethod("closeAccounts", ResourceLevel.COLLECTION);
accountsResource = getMockResource(TwitterAccountsResource.class);
StringArray emailAddresses = new StringArray("bob@test.linkedin.com", "joe@test.linkedin.com");
EasyMock.expect(accountsResource.closeAccounts(eq(emailAddresses), eq(true), eq((StringMap) null))).andReturn((new StringMap())).once();
String jsonEntityBody = RestLiTestHelper.doubleQuote("{'emailAddresses': ['bob@test.linkedin.com', 'joe@test.linkedin.com'], 'someFlag': true}");
checkInvocation(accountsResource, methodDescriptor, "POST", version, "/accounts?action=closeAccounts", jsonEntityBody);
}
use of com.linkedin.data.template.StringMap in project rest.li by linkedin.
the class TestRestLiResponseHandler method testPartialRestResponse.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "statusActionDataPartial")
public void testPartialRestResponse(AcceptTypeData acceptTypeData, String response1, String response2, ProtocolVersion protocolVersion, String errorResponseHeaderName) throws Exception {
final RestRequest request = buildRequest(acceptTypeData.acceptHeaders, protocolVersion);
RestLiResponse response;
RoutingResult routingResult1 = buildRoutingResultAction(Status.class, request, acceptTypeData.acceptHeaders);
// #1 simple record template
response = buildPartialRestResponse(request, routingResult1, buildStatusRecord());
checkResponse(response, HttpStatus.S_200_OK, 1, false, true, errorResponseHeaderName);
assertEquals(response.getEntity().toString(), response1);
// #2 DataTemplate response
StringMap map = new StringMap();
map.put("key1", "value1");
map.put("key2", "value2");
RoutingResult routingResult2 = buildRoutingResultAction(StringMap.class, request, acceptTypeData.acceptHeaders);
response = buildPartialRestResponse(request, routingResult2, map);
checkResponse(response, HttpStatus.S_200_OK, 1, false, true, errorResponseHeaderName);
// Obtain the maps necessary for comparison
final DataMap actualMap;
final DataMap expectedMap;
actualMap = response.getDataMap();
expectedMap = JACKSON_DATA_CODEC.stringToMap(response2);
assertEquals(actualMap, expectedMap);
RoutingResult routingResult3 = buildRoutingResultAction(Void.TYPE, request, acceptTypeData.acceptHeaders);
// #3 empty response
response = buildPartialRestResponse(request, routingResult3, null);
checkResponse(response, HttpStatus.S_200_OK, 1, false, false, errorResponseHeaderName);
assertEquals(response.getEntity(), null);
}
Aggregations