Skip to content
Snippets Groups Projects
Unverified Commit df2d02a8 authored by Martin Weise's avatar Martin Weise
Browse files

added metadata functionality§

parent 2ff48340
No related branches found
No related tags found
3 merge requests!81New stable release,!43Merge dev to master,!27Draft: Resolve "Zenodo Sandbox integration for PID (e.g. DOI)"
Showing
with 686 additions and 125 deletions
package at.tuwien.api.zenodo.deposit;
import com.fasterxml.jackson.annotation.JsonProperty;
public enum AccessRightDto {
@JsonProperty("open")
OPEN,
@JsonProperty("embargoed")
EMBARGOED,
@JsonProperty("restricted")
RESTRICTED,
@JsonProperty("closed")
CLOSED;
}
package at.tuwien.api.zenodo.deposit;
public enum AccessTypeDto {
OPEN("open"),
EMBARGOED("embargoed"),
RESTRICTED("restricted"),
CLOSED("closed");
private final String type;
AccessTypeDto(final String type) {
this.type = type;
}
@Override
public String toString() {
return type;
}
}
package at.tuwien.api.zenodo.deposit; package at.tuwien.api.zenodo.deposit;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.*; import lombok.*;
@Getter @Getter
...@@ -8,11 +8,9 @@ import lombok.*; ...@@ -8,11 +8,9 @@ import lombok.*;
@Builder @Builder
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
public class ContributorDto { @JsonInclude(JsonInclude.Include.NON_NULL)
public class CreatorDto {
/**
* e.g. Rauber, Andreas
*/
private String name; private String name;
private String affiliation; private String affiliation;
......
package at.tuwien.api.zenodo.deposit;
import lombok.*;
@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class DepositChangeRequestDto {
private MetadataDto metadata;
}
package at.tuwien.api.zenodo.deposit; package at.tuwien.api.zenodo.deposit;
import at.tuwien.api.zenodo.files.FileDto; import at.tuwien.api.zenodo.files.FileDto;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.*; import lombok.*;
import java.time.Instant;
import java.util.List; import java.util.List;
@Getter @Getter
...@@ -11,12 +13,13 @@ import java.util.List; ...@@ -11,12 +13,13 @@ import java.util.List;
@Builder @Builder
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
/** public class DepositChangeResponseDto {
* TODO add created, modified, embargodate with +00:00 timezone
*/
public class DepositDto {
private String description; @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSSSSXXX")
private Instant created;
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSSSSXXX")
private Instant modified;
@JsonProperty("conceptrecid") @JsonProperty("conceptrecid")
private Long conceptRecId; private Long conceptRecId;
...@@ -35,7 +38,7 @@ public class DepositDto { ...@@ -35,7 +38,7 @@ public class DepositDto {
@JsonProperty("prereserve_doi") @JsonProperty("prereserve_doi")
private Boolean prereserveDoi; private Boolean prereserveDoi;
private ContributorDto[] contributors; private CreatorDto[] contributors;
private List<FileDto> files; private List<FileDto> files;
......
package at.tuwien.api.zenodo.deposit;
import at.tuwien.api.zenodo.files.FileDto;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.*;
import java.time.Instant;
import java.time.LocalDateTime;
import java.util.List;
@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class DepositResponseDto {
/**
* {@link Instant} without timezone seems broken
*/
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSSSS")
private LocalDateTime created;
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSSSS")
private LocalDateTime modified;
private String description;
@JsonProperty("conceptrecid")
private Long conceptRecId;
private Long owner;
@JsonProperty("access_conditions")
private String accessConditions;
private String doi;
private LinksDto links;
private MetadataDto metadata;
@JsonProperty("prereserve_doi")
private Boolean prereserveDoi;
private CreatorDto[] contributors;
private List<FileDto> files;
private Long id;
@JsonProperty("record_id")
private Long recordId;
private String state;
private Boolean submitted;
private String title;
}
package at.tuwien.api.zenodo.deposit; package at.tuwien.api.zenodo.deposit;
import com.fasterxml.jackson.annotation.JsonProperty;
public enum ImageTypeDto { public enum ImageTypeDto {
FIGURE("figure"), @JsonProperty("figure")
PLOT("plot"), FIGURE,
DRAWING("drawing"),
DIAGRAM("diagram"), @JsonProperty("plot")
PHOTO("photo"), PLOT,
OTHER("other");
@JsonProperty("drawing")
DRAWING,
private final String type; @JsonProperty("diagram")
DIAGRAM,
ImageTypeDto(final String type) { @JsonProperty("photo")
this.type = type; PHOTO,
}
@Override @JsonProperty("other")
public String toString() { OTHER;
return type;
}
} }
package at.tuwien.api.zenodo.deposit; package at.tuwien.api.zenodo.deposit;
import com.fasterxml.jackson.annotation.JsonProperty;
/** /**
* @apiNote https://sandbox.zenodo.org/api/licenses/ * @apiNote https://sandbox.zenodo.org/api/licenses/
*/ */
public enum LicenseTypeDto { public enum LicenseTypeDto {
BSD("bsd-license"), @JsonProperty("bsd-license")
CC_NC("cc-nc"), BSD,
CC_BY("cc-by");
private final String type; @JsonProperty("cc-nc")
CC_NC,
LicenseTypeDto(final String type) { @JsonProperty("cc-by")
this.type = type; CC_BY,
}
@Override @JsonProperty("CC0-1.0")
public String toString() { CC0_1_0;
return type;
}
} }
package at.tuwien.api.zenodo.deposit; package at.tuwien.api.zenodo.deposit;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.*; import lombok.*;
import java.time.Instant;
import java.util.Date;
@Getter @Getter
@Setter @Setter
@Builder @Builder
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
public class MetadataDto { public class MetadataDto {
private String title;
@JsonProperty("upload_type")
private UploadTypeDto uploadType;
@JsonProperty("prereserve_doi") @JsonProperty("prereserve_doi")
private PreserveDoiDto prereserveDoi; private PreserveDoiDto prereserveDoi;
private String description;
private String doi;
// private LicenseTypeDto license;
@JsonProperty("publication_date")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")
private Date publicationDate;
@JsonProperty("access_right")
private AccessRightDto accessRight;
private CreatorDto[] creators;
} }
package at.tuwien.api.zenodo.deposit; package at.tuwien.api.zenodo.deposit;
import com.fasterxml.jackson.annotation.JsonProperty;
public enum PublicationTypeDto { public enum PublicationTypeDto {
ANNOTATION_COLLECTION("annotationcollection"), @JsonProperty("annotationcollection")
BOOK("book"), ANNOTATION_COLLECTION,
SECTION("section"),
CONFERENCE_PAPER("conferencepaper"), @JsonProperty("book")
DATA_MANAGEMENT_PLAN("datamanagementplan"), BOOK,
ARTICLE("article"),
PATENT("patent"), @JsonProperty("section")
PREPRINT("preprint"), SECTION,
PROJECT_DELIVERABLE("deliverable"),
PROJECT_MILESTONE("milestone"), @JsonProperty("conferencepaper")
PROPOSAL("proposal"), CONFERENCE_PAPER,
REPORT("report"),
SOFTWARE_DOCUMENTATION("softwaredocumentation"), @JsonProperty("datamanagementplan")
TAXONOMIC_TREATMENT("taxonomictreatment"), DATA_MANAGEMENT_PLAN,
TECHNICAL_NOTE("technicalnote"),
THESIS("thesis"), @JsonProperty("article")
WORKING_PAPER("workingpaper"), ARTICLE,
OTHER("other");
@JsonProperty("patent")
private final String type; PATENT,
PublicationTypeDto(final String type) { @JsonProperty("preprint")
this.type = type; PREPRINT,
}
@JsonProperty("deliverable")
@Override PROJECT_DELIVERABLE,
public String toString() {
return type; @JsonProperty("milestone")
} PROJECT_MILESTONE,
@JsonProperty("proposal")
PROPOSAL,
@JsonProperty("report")
REPORT,
@JsonProperty("softwaredocumentation")
SOFTWARE_DOCUMENTATION,
@JsonProperty("taxonomictreatment")
TAXONOMIC_TREATMENT,
@JsonProperty("technicalnote")
TECHNICAL_NOTE,
@JsonProperty("thesis")
THESIS,
@JsonProperty("workingpaper")
WORKING_PAPER,
@JsonProperty("other")
OTHER;
} }
package at.tuwien.api.zenodo.deposit; package at.tuwien.api.zenodo.deposit;
import com.fasterxml.jackson.annotation.JsonProperty;
public enum UploadTypeDto { public enum UploadTypeDto {
PUBLICATION("publication"), @JsonProperty("publication")
POSTER("poster"), PUBLICATION,
PRESENTATION("presentation"),
DATASET("dataset"), @JsonProperty("poster")
IMAGE("image"), POSTER,
VIDEO("video"),
SOFTWARE("software"), @JsonProperty("presentation")
LESSON("lesson"), PRESENTATION,
PHYSICAL_OBJECT("physicalobject"),
OTHER("other"); @JsonProperty("dataset")
DATASET,
private final String type;
@JsonProperty("image")
UploadTypeDto(final String type) { IMAGE,
this.type = type;
} @JsonProperty("video")
VIDEO,
@Override
public String toString() { @JsonProperty("software")
return type; SOFTWARE,
}
@JsonProperty("lesson")
LESSON,
@JsonProperty("physicalobject")
PHYSICAL_OBJECT,
@JsonProperty("other")
OTHER;
} }
package at.tuwien.endpoints;
import at.tuwien.service.MetadataService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@Log4j2
@CrossOrigin(origins = "*")
@RestController
@RequestMapping("/api/database/{id}/table/{tableid}/file")
public class FileEndpoint {
private final MetadataService citationService;
@Autowired
public FileEndpoint(MetadataService citationService) {
this.citationService = citationService;
}
}
package at.tuwien.endpoints; package at.tuwien.endpoints;
import at.tuwien.service.CitationService; import at.tuwien.service.MetadataService;
import lombok.extern.log4j.Log4j2; import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
...@@ -8,13 +8,13 @@ import org.springframework.web.bind.annotation.*; ...@@ -8,13 +8,13 @@ import org.springframework.web.bind.annotation.*;
@Log4j2 @Log4j2
@CrossOrigin(origins = "*") @CrossOrigin(origins = "*")
@RestController @RestController
@RequestMapping("/api/database/{id}/table/{tableid}/cite") @RequestMapping("/api/database/{id}/table/{tableid}/metadata")
public class CitationEndpoint { public class MetadataEndpoint {
private final CitationService citationService; private final MetadataService citationService;
@Autowired @Autowired
public CitationEndpoint(CitationService citationService) { public MetadataEndpoint(MetadataService citationService) {
this.citationService = citationService; this.citationService = citationService;
} }
......
package at.tuwien; package at.tuwien;
import at.tuwien.api.zenodo.deposit.ContributorDto; import at.tuwien.api.zenodo.deposit.*;
import at.tuwien.api.zenodo.deposit.DepositDto;
import at.tuwien.api.zenodo.deposit.LicenseTypeDto;
import at.tuwien.api.zenodo.files.FileDto; import at.tuwien.api.zenodo.files.FileDto;
import at.tuwien.api.zenodo.files.FileLinksDto; import at.tuwien.api.zenodo.files.FileLinksDto;
import org.apache.commons.lang.RandomStringUtils; import org.apache.commons.lang.RandomStringUtils;
import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.TestPropertySource;
import java.time.Instant; import java.time.Instant;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit; import java.time.temporal.ChronoUnit;
import java.util.List; import java.util.List;
...@@ -28,8 +25,17 @@ public abstract class BaseUnitTest { ...@@ -28,8 +25,17 @@ public abstract class BaseUnitTest {
public final static Long DEPOSIT_1_CONCEPT_RECORD_ID = 143L; public final static Long DEPOSIT_1_CONCEPT_RECORD_ID = 143L;
public final static Long DEPOSIT_1_OWNER = 144L; public final static Long DEPOSIT_1_OWNER = 144L;
public final static String CONTRIBUTOR_1_NAME = "von Goethe, Johann Wolfang"; public final static String METADATA_1_TITLE = "My super dataset";
public final static String CONTRIBUTOR_1_AFFILIATION = "Universität Leipzig"; public final static UploadTypeDto METADATA_1_UPLOAD_TYPE = UploadTypeDto.DATASET;
public final static String METADATA_1_DESCRIPTION = "The dataset contains 1000 records of ...";
public final static String CREATOR_1_NAME = "First1 Last1";
public final static String CREATOR_1_AFFIL = "TU Wien";
public final static String CREATOR_1_ORCID = "0000-0002-5713-0725";
public final static String CREATOR_2_NAME = "First2 Last2";
public final static String CREATOR_2_AFFIL = "TU Graz";
public final static String CREATOR_2_ORCID = "0000-0002-2606-4059";
public final static Long DEPOSIT_2_ID = 2L; public final static Long DEPOSIT_2_ID = 2L;
public final static String DEPOSIT_2_TITLE = "Test Document " + RandomStringUtils.randomAlphanumeric(10); public final static String DEPOSIT_2_TITLE = "Test Document " + RandomStringUtils.randomAlphanumeric(10);
...@@ -52,31 +58,56 @@ public abstract class BaseUnitTest { ...@@ -52,31 +58,56 @@ public abstract class BaseUnitTest {
public final static String DEPOSIT_1_DOI = "10.5072/zenodo.542201"; public final static String DEPOSIT_1_DOI = "10.5072/zenodo.542201";
public final static Long DEPOSIT_1_REC_ID = 542201L; public final static Long DEPOSIT_1_REC_ID = 542201L;
public final static FileLinksDto FILE_1_LINKS_DTO = FileLinksDto.builder() public final static CreatorDto CREATOR_1 = CreatorDto.builder()
.name(CREATOR_1_NAME)
.affiliation(CREATOR_1_AFFIL)
.orcid(CREATOR_1_ORCID)
.build();
public final static CreatorDto CREATOR_2 = CreatorDto.builder()
.name(CREATOR_2_NAME)
.affiliation(CREATOR_2_AFFIL)
.orcid(CREATOR_2_ORCID)
.build();
public final static MetadataDto METADATA_1 = MetadataDto.builder()
.creators(new CreatorDto[]{CREATOR_1, CREATOR_2})
.description(METADATA_1_DESCRIPTION)
.title(METADATA_1_TITLE)
.uploadType(METADATA_1_UPLOAD_TYPE)
.build();
public final static FileLinksDto FILE_1_LINKS = FileLinksDto.builder()
.download(FILE_1_LINKS_DOWNLOAD) .download(FILE_1_LINKS_DOWNLOAD)
.self(FILE_1_LINKS_SELF) .self(FILE_1_LINKS_SELF)
.build(); .build();
public final static FileDto FILE_1_DTO = FileDto.builder() public final static FileDto FILE_1 = FileDto.builder()
.checksum(FILE_1_CHECKSUM) .checksum(FILE_1_CHECKSUM)
.filename(FILE_1_NAME) .filename(FILE_1_NAME)
.id(FILE_1_ID) .id(FILE_1_ID)
.filesize(FILE_1_SIZE) .filesize(FILE_1_SIZE)
.links(FILE_1_LINKS_DTO) .links(FILE_1_LINKS)
.build(); .build();
public final static DepositDto DEPOSIT_1_RETURN_DTO = DepositDto.builder() public final static DepositChangeResponseDto DEPOSIT_1 = DepositChangeResponseDto.builder()
.id(DEPOSIT_1_ID) .id(DEPOSIT_1_ID)
.created(DEPOSIT_1_CREATED)
.modified(DEPOSIT_1_MODIFIED)
.title(DEPOSIT_1_TITLE) .title(DEPOSIT_1_TITLE)
.state(DEPOSIT_1_STATE) .state(DEPOSIT_1_STATE)
.submitted(DEPOSIT_1_SUBMITTED) .submitted(DEPOSIT_1_SUBMITTED)
.recordId(DEPOSIT_1_RECORD_ID) .recordId(DEPOSIT_1_RECORD_ID)
.files(List.of(FILE_1_DTO)) .files(List.of(FILE_1))
.build(); .build();
public final static ContributorDto CONTRIBUTOR_1_DTO = ContributorDto.builder() public final static DepositResponseDto DEPOSIT_2 = DepositResponseDto.builder()
.name(CONTRIBUTOR_1_NAME) .id(DEPOSIT_1_ID)
.affiliation(CONTRIBUTOR_1_AFFILIATION) .title(DEPOSIT_1_TITLE)
.state(DEPOSIT_1_STATE)
.submitted(DEPOSIT_1_SUBMITTED)
.recordId(DEPOSIT_1_RECORD_ID)
.files(List.of(FILE_1))
.build(); .build();
} }
package at.tuwien.mapper;
import at.tuwien.BaseUnitTest;
import at.tuwien.api.zenodo.deposit.DepositChangeResponseDto;
import at.tuwien.api.zenodo.deposit.DepositResponseDto;
import at.tuwien.config.ReadyConfig;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.io.FileUtils;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.util.ResourceUtils;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import static org.junit.jupiter.api.Assertions.assertEquals;
@SpringBootTest
public class MapperUnitTest extends BaseUnitTest {
@MockBean
private ReadyConfig readyConfig;
@Autowired
private ObjectMapper objectMapper;
@Test
public void listDeposits_success() throws IOException {
final String json = FileUtils.readFileToString(ResourceUtils.getFile("classpath:zenodo-deposits-list.json"));
/* test */
final DepositResponseDto[] response = objectMapper.readValue(json, DepositResponseDto[].class);
assertEquals(10, response.length);
}
@Test
public void storeDeposits_success() throws IOException, URISyntaxException {
final String json = FileUtils.readFileToString(ResourceUtils.getFile("classpath:zenodo-deposits-store.json"));
/* test */
final DepositChangeResponseDto response = objectMapper.readValue(json, DepositChangeResponseDto.class);
assertEquals(926290, response.getConceptRecId());
assertEquals(0, response.getFiles().size());
assertEquals(926291, response.getId());
assertEquals(new URI("https://sandbox.zenodo.org/api/files/dbea7621-8308-45af-b6af-9e12394dcc1b"), response.getLinks().getBucket());
assertEquals(new URI("https://sandbox.zenodo.org/deposit/926291"), response.getLinks().getHtml());
assertEquals(new URI("https://sandbox.zenodo.org/api/deposit/depositions/926291/actions/discard"), response.getLinks().getDiscard());
assertEquals(new URI("https://sandbox.zenodo.org/api/deposit/depositions/926291/actions/edit"), response.getLinks().getEdit());
assertEquals(new URI("https://sandbox.zenodo.org/api/deposit/depositions/926291/files"), response.getLinks().getFiles());
assertEquals(new URI("https://sandbox.zenodo.org/api/deposit/depositions/926291/actions/publish"), response.getLinks().getPublish());
assertEquals(new URI("https://sandbox.zenodo.org/api/deposit/depositions/926291"), response.getLinks().getSelf());
assertEquals("10.5072/zenodo.926291", response.getMetadata().getPrereserveDoi().getDoi());
assertEquals(93513L, response.getOwner());
assertEquals(926291L, response.getRecordId());
assertEquals("unsubmitted", response.getState());
assertEquals(false, response.getSubmitted());
assertEquals("", response.getTitle());
}
}
\ No newline at end of file
package at.tuwien.service; package at.tuwien.service;
import at.tuwien.BaseUnitTest; import at.tuwien.BaseUnitTest;
import at.tuwien.api.zenodo.deposit.DepositDto; import at.tuwien.api.zenodo.deposit.*;
import at.tuwien.config.ReadyConfig; import at.tuwien.config.ReadyConfig;
import at.tuwien.exception.ZenodoApiException; import at.tuwien.exception.ZenodoApiException;
import at.tuwien.exception.ZenodoAuthenticationException; import at.tuwien.exception.ZenodoAuthenticationException;
import at.tuwien.exception.ZenodoNotFoundException;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
...@@ -12,22 +13,16 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -12,22 +13,16 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.web.client.RestTemplate;
import java.util.List;
@SpringBootTest @SpringBootTest
@ExtendWith(SpringExtension.class) @ExtendWith(SpringExtension.class)
public class ZenodoServiceIntegrationTest extends BaseUnitTest { public class MetadataServiceIntegrationTest extends BaseUnitTest {
@MockBean @MockBean
private ReadyConfig readyConfig; private ReadyConfig readyConfig;
@Autowired @Autowired
private ZenodoService zenodoService; private ZenodoMetadataService zenodoService;
@Autowired
private RestTemplate zenodoTemplate;
@Test @Test
public void listDeposit_succeeds() throws ZenodoApiException, ZenodoAuthenticationException { public void listDeposit_succeeds() throws ZenodoApiException, ZenodoAuthenticationException {
...@@ -40,8 +35,24 @@ public class ZenodoServiceIntegrationTest extends BaseUnitTest { ...@@ -40,8 +35,24 @@ public class ZenodoServiceIntegrationTest extends BaseUnitTest {
public void createDeposit_succeeds() throws ZenodoApiException, ZenodoAuthenticationException { public void createDeposit_succeeds() throws ZenodoApiException, ZenodoAuthenticationException {
/* test */ /* test */
final DepositDto response = zenodoService.storeCitation(); final DepositChangeResponseDto response = zenodoService.storeCitation();
Assertions.assertNotNull(response.getId()); Assertions.assertNotNull(response.getId());
} }
@Test
public void updateDeposit_succeeds() throws ZenodoApiException, ZenodoAuthenticationException,
ZenodoNotFoundException {
final DepositChangeRequestDto request = DepositChangeRequestDto.builder()
.metadata(METADATA_1)
.build();
final DepositChangeResponseDto response = zenodoService.storeCitation();
/* test */
final DepositChangeResponseDto response2 = zenodoService.updateCitation(response.getId(), request);
Assertions.assertNotNull(response2.getId());
Assertions.assertEquals(METADATA_1_TITLE, response2.getTitle());
Assertions.assertEquals(METADATA_1_TITLE, response2.getMetadata().getTitle());
Assertions.assertEquals(METADATA_1_DESCRIPTION, response2.getMetadata().getDescription());
}
} }
\ No newline at end of file
package at.tuwien.service; package at.tuwien.service;
import at.tuwien.BaseUnitTest; import at.tuwien.BaseUnitTest;
import at.tuwien.api.zenodo.deposit.DepositDto; import at.tuwien.api.zenodo.deposit.DepositChangeResponseDto;
import at.tuwien.api.zenodo.deposit.DepositResponseDto;
import at.tuwien.api.zenodo.deposit.DepositChangeRequestDto;
import at.tuwien.api.zenodo.deposit.MetadataDto;
import at.tuwien.config.ReadyConfig; import at.tuwien.config.ReadyConfig;
import at.tuwien.exception.ZenodoApiException; import at.tuwien.exception.ZenodoApiException;
import at.tuwien.exception.ZenodoAuthenticationException; import at.tuwien.exception.ZenodoAuthenticationException;
import at.tuwien.exception.ZenodoNotFoundException;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mockito; import org.mockito.Mockito;
...@@ -28,30 +32,30 @@ import static org.mockito.Mockito.*; ...@@ -28,30 +32,30 @@ import static org.mockito.Mockito.*;
@SpringBootTest @SpringBootTest
@ExtendWith(SpringExtension.class) @ExtendWith(SpringExtension.class)
public class ZenodoServiceUnitTest extends BaseUnitTest { public class MetadataServiceUnitTest extends BaseUnitTest {
@MockBean @MockBean
private ReadyConfig readyConfig; private ReadyConfig readyConfig;
@Autowired @Autowired
private ZenodoService zenodoService; private ZenodoMetadataService zenodoService;
@MockBean @MockBean
private RestTemplate zenodoTemplate; private RestTemplate zenodoTemplate;
@Test @Test
public void listCitations_succeeds() throws ZenodoApiException, ZenodoAuthenticationException { public void listCitations_succeeds() throws ZenodoApiException, ZenodoAuthenticationException {
when(zenodoTemplate.exchange(anyString(), eq(HttpMethod.GET), eq(null), eq(DepositDto[].class), anyString())) when(zenodoTemplate.exchange(anyString(), eq(HttpMethod.GET), eq(null), eq(DepositResponseDto[].class), anyString()))
.thenReturn(ResponseEntity.ok(new DepositDto[]{DEPOSIT_1_RETURN_DTO})); .thenReturn(ResponseEntity.ok(new DepositResponseDto[]{DEPOSIT_2}));
/* test */ /* test */
final List<DepositDto> response = zenodoService.listCitations(); final List<DepositResponseDto> response = zenodoService.listCitations();
assertEquals(1, response.size()); assertEquals(1, response.size());
} }
@Test @Test
public void listCitations_empty_fails() { public void listCitations_empty_fails() {
when(zenodoTemplate.exchange(anyString(), eq(HttpMethod.GET), eq(null), eq(DepositDto[].class), anyString())) when(zenodoTemplate.exchange(anyString(), eq(HttpMethod.GET), eq(null), eq(DepositResponseDto[].class), anyString()))
.thenReturn(ResponseEntity.ok().build()); .thenReturn(ResponseEntity.ok().build());
/* test */ /* test */
...@@ -62,20 +66,82 @@ public class ZenodoServiceUnitTest extends BaseUnitTest { ...@@ -62,20 +66,82 @@ public class ZenodoServiceUnitTest extends BaseUnitTest {
@Test @Test
public void storeCitation_succeed() throws ZenodoApiException, ZenodoAuthenticationException { public void storeCitation_succeed() throws ZenodoApiException, ZenodoAuthenticationException {
when(zenodoTemplate.exchange(anyString(), eq(HttpMethod.POST), Mockito.<HttpEntity<String>>any(), eq(DepositDto.class), anyString())) when(zenodoTemplate.exchange(anyString(), eq(HttpMethod.POST), Mockito.<HttpEntity<String>>any(), eq(DepositChangeResponseDto.class), anyString()))
.thenReturn(ResponseEntity.status(HttpStatus.CREATED) .thenReturn(ResponseEntity.status(HttpStatus.CREATED)
.body(DEPOSIT_1_RETURN_DTO)); .body(DEPOSIT_1));
/* test */ /* test */
final DepositDto response = zenodoService.storeCitation(); final DepositChangeResponseDto response = zenodoService.storeCitation();
assertEquals(DEPOSIT_1_CREATED, response.getCreated());
assertEquals(DEPOSIT_1_MODIFIED, response.getModified());
} }
@Test @Test
public void deleteCitation_succeeds() { public void deleteCitation_succeeds() throws ZenodoApiException, ZenodoAuthenticationException {
when(zenodoTemplate.exchange(anyString(), eq(HttpMethod.DELETE), eq(null), eq(String.class), anyLong(), anyString()))
.thenReturn(ResponseEntity.status(HttpStatus.CREATED)
.build());
/* test */
zenodoService.deleteCitation(DEPOSIT_1_ID);
}
@Test
public void deleteCitation_fails() {
when(zenodoTemplate.exchange(anyString(), eq(HttpMethod.DELETE), eq(null), eq(String.class), anyLong(), anyString()))
.thenReturn(ResponseEntity.status(HttpStatus.OK)
.build());
/* test */
assertThrows(ZenodoApiException.class, () -> {
zenodoService.deleteCitation(DEPOSIT_1_ID);
});
}
@Test
public void updateCitation_succeeds() throws ZenodoApiException, ZenodoAuthenticationException,
ZenodoNotFoundException {
final DepositChangeRequestDto request = DepositChangeRequestDto.builder()
.metadata(METADATA_1)
.build();
when(zenodoTemplate.exchange(anyString(), eq(HttpMethod.PUT), Mockito.<HttpEntity<DepositChangeRequestDto>>any(), eq(DepositChangeResponseDto.class), eq(DEPOSIT_1_ID), anyString()))
.thenReturn(ResponseEntity.status(HttpStatus.OK)
.body(DEPOSIT_1));
/* test */
zenodoService.updateCitation(DEPOSIT_1_ID, request);
}
@Test
public void updateCitation_only1orcid_fails() {
final MetadataDto m = METADATA_1;
m.getCreators()[1].setOrcid(null);
final DepositChangeRequestDto request = DepositChangeRequestDto.builder()
.metadata(m)
.build();
when(zenodoTemplate.exchange(anyString(), eq(HttpMethod.PUT), Mockito.<HttpEntity<DepositChangeRequestDto>>any(), eq(DepositChangeResponseDto.class), eq(DEPOSIT_1_ID), anyString()))
.thenReturn(ResponseEntity.status(HttpStatus.BAD_REQUEST)
.build());
/* test */
assertThrows(ZenodoNotFoundException.class, () -> {
zenodoService.updateCitation(DEPOSIT_1_ID, request);
});
} }
@Test @Test
public void deleteCitation_noId_fails() { public void updateCitation_notExists_fails() {
final DepositChangeRequestDto request = DepositChangeRequestDto.builder()
.metadata(METADATA_1)
.build();
when(zenodoTemplate.exchange(anyString(), eq(HttpMethod.PUT), Mockito.<HttpEntity<DepositChangeRequestDto>>any(), eq(DepositChangeResponseDto.class), eq(DEPOSIT_1_ID), anyString()))
.thenReturn(ResponseEntity.status(HttpStatus.BAD_REQUEST)
.build());
/* test */
assertThrows(ZenodoNotFoundException.class, () -> {
zenodoService.updateCitation(DEPOSIT_1_ID, request);
});
} }
} }
\ No newline at end of file
#!/usr/bin/env python3
import socket
HOST = '' # Symbolic name meaning all available interfaces
PORT = 50000 # Arbitrary non-privileged port
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))
s.listen(1)
conn, addr = s.accept()
print ('Connected by' + str(addr))
while 1:
data = conn.recv(1024)
if not data: break
print("===> recv " + str(data))
conn.close()
\ No newline at end of file
{
"conceptrecid": "926290",
"created": "2021-09-28T13:56:35.790196+00:00",
"files": [],
"id": 926291,
"links": {
"bucket": "https://sandbox.zenodo.org/api/files/dbea7621-8308-45af-b6af-9e12394dcc1b",
"discard": "https://sandbox.zenodo.org/api/deposit/depositions/926291/actions/discard",
"edit": "https://sandbox.zenodo.org/api/deposit/depositions/926291/actions/edit",
"files": "https://sandbox.zenodo.org/api/deposit/depositions/926291/files",
"html": "https://sandbox.zenodo.org/deposit/926291",
"latest_draft": "https://sandbox.zenodo.org/api/deposit/depositions/926291",
"latest_draft_html": "https://sandbox.zenodo.org/deposit/926291",
"publish": "https://sandbox.zenodo.org/api/deposit/depositions/926291/actions/publish",
"self": "https://sandbox.zenodo.org/api/deposit/depositions/926291"
},
"metadata": {
"prereserve_doi": {
"doi": "10.5072/zenodo.926291",
"recid": 926291
}
},
"modified": "2021-09-28T13:56:35.790216+00:00",
"owner": 93513,
"record_id": 926291,
"state": "unsubmitted",
"submitted": false,
"title": ""
}
\ No newline at end of file
{
"conceptrecid": "926408",
"created": "2021-09-28T15:52:19.833120+00:00",
"doi": "",
"doi_url": "https://doi.org/",
"files": [],
"id": 926409,
"links": {
"bucket": "https://sandbox.zenodo.org/api/files/5e50707f-e9f2-4de7-aed1-28bd7ddcdff8",
"discard": "https://sandbox.zenodo.org/api/deposit/depositions/926409/actions/discard",
"edit": "https://sandbox.zenodo.org/api/deposit/depositions/926409/actions/edit",
"files": "https://sandbox.zenodo.org/api/deposit/depositions/926409/files",
"html": "https://sandbox.zenodo.org/deposit/926409",
"latest_draft": "https://sandbox.zenodo.org/api/deposit/depositions/926409",
"latest_draft_html": "https://sandbox.zenodo.org/deposit/926409",
"newversion": "https://sandbox.zenodo.org/api/deposit/depositions/926409/actions/newversion",
"publish": "https://sandbox.zenodo.org/api/deposit/depositions/926409/actions/publish",
"registerconceptdoi": "https://sandbox.zenodo.org/api/deposit/depositions/926409/actions/registerconceptdoi",
"self": "https://sandbox.zenodo.org/api/deposit/depositions/926409"
},
"metadata": {
"access_right": "open",
"creators": [
{
"affiliation": "TU Wien",
"name": "First1 Last1",
"orcid": "0000-0002-5713-0725"
},
{
"affiliation": "TU Graz",
"name": "First2 Last2",
"orcid": "0000-0002-2606-4059"
}
],
"description": "The dataset contains 1000 records of ...",
"doi": "",
"license": "CC0-1.0",
"prereserve_doi": {
"doi": "10.5072/zenodo.926409",
"recid": 926409
},
"publication_date": "2021-09-28",
"title": "My super dataset",
"upload_type": "dataset"
},
"modified": "2021-09-28T15:52:20.135553+00:00",
"owner": 93513,
"record_id": 926409,
"state": "unsubmitted",
"submitted": false,
"title": "My super dataset"
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment