default values and forced indexing
This commit is contained in:
@@ -5,7 +5,9 @@ import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -21,7 +23,7 @@ import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.http.client.BufferingClientHttpRequestFactory;
|
||||
import org.springframework.http.client.ClientHttpRequestInterceptor;
|
||||
import org.springframework.http.client.SimpleClientHttpRequestFactory;
|
||||
import org.springframework.web.client.HttpClientErrorException;
|
||||
import org.springframework.web.client.HttpStatusCodeException;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import com.bayer.edam.migration.adam.Token;
|
||||
@@ -35,9 +37,7 @@ public class MamMigrationSelective implements CommandLineRunner {
|
||||
private static final Logger log = LoggerFactory.getLogger(MamMigrationSelective.class);
|
||||
|
||||
static String adamHost = "https://edam-q.bayer.com:2015";
|
||||
static int[] selection = { 71948 }; // { 71048, 70778, 70746
|
||||
// ,70142,70361,63924,71263,63201,56942,57641,70745,70440,70340,70288,71725 */
|
||||
// };
|
||||
static int[] selection = { 71948, 71048,70778/*,70746,70142,70361,63924,71263,63201,56942,57641,70745,70440,70340,70288,71725*/};
|
||||
|
||||
@Value("${mam.auth}")
|
||||
private String mamAuth;
|
||||
@@ -51,6 +51,8 @@ public class MamMigrationSelective implements CommandLineRunner {
|
||||
|
||||
private static SimpleDateFormat isoDate = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'");
|
||||
private static SimpleDateFormat stringDate = new SimpleDateFormat("yyyy-MM-dd");
|
||||
|
||||
private List<String> locations = new ArrayList<String>();
|
||||
|
||||
@Override
|
||||
public void run(String... strings) throws Exception {
|
||||
@@ -74,9 +76,16 @@ public class MamMigrationSelective implements CommandLineRunner {
|
||||
.getBody();
|
||||
|
||||
// log.info(entry.toFullString());
|
||||
|
||||
|
||||
postToAdam(entry);
|
||||
}
|
||||
|
||||
// delete all created records
|
||||
// for (String location : locations) {
|
||||
// ResponseEntity<String> response = restTemplate.exchange(adamHost + location, HttpMethod.DELETE,
|
||||
// adamHeadersEntity, String.class);
|
||||
// log.info("Deleted " + location + ": " + response.toString());
|
||||
// }
|
||||
|
||||
invalidateAdamToken();
|
||||
}
|
||||
@@ -110,6 +119,7 @@ public class MamMigrationSelective implements CommandLineRunner {
|
||||
record.addField("byr_Title", entry.name.get("en"));
|
||||
record.addField("byr_ah_projectLead", Collections.singletonList(Definitions.defaultProjectLead));
|
||||
record.addField("byr_ah_licenseHolderList", Collections.singletonList(Definitions.defaultLicenseHolder));
|
||||
record.addField("byr_ah_licenseAdditionalPermittedUse", Collections.singletonList(Definitions.defaultAdditionalPermittedUse));
|
||||
|
||||
// Description / Additional Information
|
||||
String description = entry.description.get("en");
|
||||
@@ -130,20 +140,21 @@ public class MamMigrationSelective implements CommandLineRunner {
|
||||
// TODO
|
||||
|
||||
// Keywords
|
||||
List<String> keywords = Arrays.asList(entry.keyword.get("en").split("\\s*,\\s*"));
|
||||
record.addField("byr_ah_keywords_tl", keywords);
|
||||
if (entry.keyword.get("en") != null && entry.keyword.get("en").length() > 0) {
|
||||
Set<String> keywords = new HashSet<String>(Arrays.asList(entry.keyword.get("en").split("\\s*,\\s*")));
|
||||
record.addField("byr_ah_keywords_tl", new ArrayList<String>(keywords));
|
||||
}
|
||||
|
||||
HttpEntity<WriteRecord> httpEntity = new HttpEntity<WriteRecord>(record, adamHeaders);
|
||||
try {
|
||||
URI location = restTemplate.postForLocation(adamHost + "/records", httpEntity, WriteRecord.class);
|
||||
log.info("Location: " + location);
|
||||
|
||||
ResponseEntity<String> response = restTemplate.exchange(adamHost + location, HttpMethod.DELETE,
|
||||
adamHeadersEntity, String.class);
|
||||
log.info("Deleted record: " + response.toString());
|
||||
} catch (HttpClientErrorException hcee) {
|
||||
log.error(hcee.getStatusCode().toString());
|
||||
log.error(hcee.getResponseBodyAsString());
|
||||
log.info("Created " + location);
|
||||
|
||||
locations.add(location.toString());
|
||||
|
||||
} catch (HttpStatusCodeException hsce) {
|
||||
log.error(hsce.getStatusCode().toString());
|
||||
log.error(hsce.getResponseBodyAsString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -164,6 +175,7 @@ public class MamMigrationSelective implements CommandLineRunner {
|
||||
headers.add("Accept", "application/hal+json");
|
||||
headers.add("Content-Type", "application/json");
|
||||
headers.add("Authorization", "Basic " + adamAuth);
|
||||
headers.add("set-immediateSearchIndexUpdate", "true"); // see https://edam.bayer.com:2015/docs/resources/record#example-records-direct-push
|
||||
HttpEntity<String> entity = new HttpEntity<String>("", headers);
|
||||
Token token = restTemplate.exchange(adamHost + "/auth", HttpMethod.GET, entity, Token.class).getBody();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user