-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8daea6b
commit d6bce7f
Showing
10 changed files
with
375 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/main/java/nl/knaw/dans/dvingest/config/IngestConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright (C) 2024 DANS - Data Archiving and Networked Services ([email protected]) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package nl.knaw.dans.dvingest.config; | ||
|
||
import lombok.Data; | ||
|
||
import java.nio.file.Path; | ||
|
||
@Data | ||
public class IngestConfig { | ||
private Path inbox; | ||
private Path outbox; | ||
private Path tempDir; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright (C) 2024 DANS - Data Archiving and Networked Services ([email protected]) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package nl.knaw.dans.dvingest.core; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
import lombok.ToString; | ||
import nl.knaw.dans.validation.Uuid; | ||
|
||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.Id; | ||
import javax.persistence.Table; | ||
import java.nio.file.Path; | ||
|
||
/** | ||
* Description of an import job. | ||
*/ | ||
@Entity | ||
@Table(name = "import_job") | ||
@Getter | ||
@Setter | ||
@ToString | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class ImportJob { | ||
@GeneratedValue | ||
@Id | ||
private Long id; | ||
|
||
@Column(name = "creation_time") | ||
private Long creationTime; | ||
|
||
@Column(name = "uuid") | ||
@Uuid | ||
private String uuid; | ||
|
||
@Column(name = "status") | ||
private String status; | ||
|
||
@Column(name = "location") | ||
private String location; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Copyright (C) 2024 DANS - Data Archiving and Networked Services ([email protected]) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package nl.knaw.dans.dvingest.core; | ||
|
||
public interface ImportTask { | ||
|
||
|
||
|
||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/nl/knaw/dans/dvingest/core/ImportTaskFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright (C) 2024 DANS - Data Archiving and Networked Services ([email protected]) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package nl.knaw.dans.dvingest.core; | ||
|
||
import nl.knaw.dans.dvingest.api.ImportCommandDto; | ||
|
||
public class ImportTaskFactory { | ||
|
||
public ImportTask createImportTask(ImportCommandDto importCommandDto) { | ||
return null; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/nl/knaw/dans/dvingest/core/ImportTaskProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Copyright (C) 2024 DANS - Data Archiving and Networked Services ([email protected]) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package nl.knaw.dans.dvingest.core; | ||
|
||
public class ImportTaskProcessor { | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Copyright (C) 2024 DANS - Data Archiving and Networked Services ([email protected]) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package nl.knaw.dans.dvingest.db; | ||
|
||
import io.dropwizard.hibernate.AbstractDAO; | ||
import nl.knaw.dans.dvingest.core.ImportJob; | ||
import org.hibernate.SessionFactory; | ||
import org.hibernate.exception.ConstraintViolationException; | ||
|
||
import javax.persistence.OptimisticLockException; | ||
import javax.persistence.criteria.CriteriaBuilder; | ||
import javax.persistence.criteria.CriteriaQuery; | ||
import javax.persistence.criteria.Root; | ||
import java.util.Optional; | ||
|
||
public class ImportJobDao extends AbstractDAO<ImportJob> { | ||
public ImportJobDao(SessionFactory sessionFactory) { | ||
super(sessionFactory); | ||
} | ||
|
||
public ImportJob save(ImportJob importJob) { | ||
try { | ||
if (importJob.getId() == null || get(importJob.getId()) == null) { | ||
persist(importJob); | ||
} | ||
else { | ||
currentSession().update(importJob); | ||
} | ||
return importJob; | ||
} | ||
catch (ConstraintViolationException e) { | ||
throw new IllegalArgumentException(e.getSQLException().getMessage()); | ||
} | ||
catch (OptimisticLockException e) { | ||
throw new IllegalStateException("Failed to update ImportJob due to concurrent modification", e); | ||
} | ||
} | ||
|
||
public Optional<ImportJob> findById(Long id) { | ||
return Optional.ofNullable(get(id)); | ||
} | ||
|
||
public Optional<ImportJob> findByUuid(String uuid) { | ||
CriteriaBuilder builder = currentSession().getCriteriaBuilder(); | ||
CriteriaQuery<ImportJob> query = builder.createQuery(ImportJob.class); | ||
Root<ImportJob> root = query.from(ImportJob.class); | ||
query.select(root).where(builder.equal(root.get("uuid"), uuid)); | ||
|
||
return Optional.ofNullable(currentSession().createQuery(query).uniqueResult()); | ||
} | ||
|
||
public Optional<ImportJob> getNextJob() { | ||
CriteriaBuilder builder = currentSession().getCriteriaBuilder(); | ||
CriteriaQuery<ImportJob> query = builder.createQuery(ImportJob.class); | ||
Root<ImportJob> root = query.from(ImportJob.class); | ||
query.select(root).where(builder.equal(root.get("status"), "PENDING")).orderBy(builder.desc(root.get("creationTime"))); | ||
|
||
return Optional.ofNullable(currentSession().createQuery(query).setMaxResults(1).uniqueResult()); | ||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/nl/knaw/dans/dvingest/resources/IngestApiResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright (C) 2024 DANS - Data Archiving and Networked Services ([email protected]) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package nl.knaw.dans.dvingest.resources; | ||
|
||
import nl.knaw.dans.dvingest.api.ImportCommandDto; | ||
|
||
import javax.ws.rs.core.Response; | ||
|
||
public class IngestApiResource implements IngestApi { | ||
@Override | ||
public Response ingestPost(ImportCommandDto importCommandDto) { | ||
return null; | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
src/test/java/nl/knaw/dans/dvingest/db/ImportJobDaoTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright (C) 2024 DANS - Data Archiving and Networked Services ([email protected]) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package nl.knaw.dans.dvingest.db; | ||
|
||
import io.dropwizard.testing.junit5.DAOTestExtension; | ||
import io.dropwizard.testing.junit5.DropwizardExtensionsSupport; | ||
import nl.knaw.dans.dvingest.core.ImportJob; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
|
||
import java.nio.file.Path; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
@ExtendWith(DropwizardExtensionsSupport.class) | ||
public class ImportJobDaoTest { | ||
private final DAOTestExtension db = DAOTestExtension.newBuilder() | ||
.addEntityClass(ImportJob.class) | ||
.build(); | ||
private final ImportJobDao dao = new ImportJobDao(db.getSessionFactory()); | ||
|
||
@Test | ||
public void create_should_save_ImportJob() { | ||
var uuid = "f797a6a9-2a85-4f26-af62-b3eaae724497"; | ||
|
||
db.inTransaction(() -> { | ||
var importJob = new ImportJob(); | ||
importJob.setLocation("path"); | ||
importJob.setUuid(uuid); | ||
importJob.setStatus("status"); | ||
importJob.setCreationTime(123L); | ||
dao.save(importJob); | ||
}); | ||
|
||
db.inTransaction(() -> { | ||
var result = dao.findByUuid(uuid); | ||
assertThat(result).isPresent(); | ||
assertThat(result.get().getLocation()).isEqualTo("path"); | ||
assertThat(result.get().getUuid()).isEqualTo(uuid); | ||
assertThat(result.get().getStatus()).isEqualTo("status"); | ||
assertThat(result.get().getCreationTime()).isEqualTo(123L); | ||
}); | ||
} | ||
|
||
} |