Browse Source

Implemented getSystem method end-to-end

master
Jim Martens 10 months ago
parent
commit
8968ecc536
  1. 33
      oparl-server/src/main/java/de/twomartens/oparlservice/entity/internal/System.java
  2. 60
      oparl-server/src/main/java/de/twomartens/oparlservice/repository/SystemRepository.java
  3. 47
      oparl-server/src/main/java/de/twomartens/oparlservice/service/OParlService.java

33
oparl-server/src/main/java/de/twomartens/oparlservice/entity/internal/System.java

@ -2,23 +2,30 @@ package de.twomartens.oparlservice.entity.internal;
import lombok.*;
import javax.persistence.*;
import java.time.ZonedDateTime;
@Getter
@Setter
@ToString
@EqualsAndHashCode
@RequiredArgsConstructor
@AllArgsConstructor
@NoArgsConstructor
@Entity
@Table(name = "systems")
public class System {
private final int id;
private final String license;
private final String name;
private final String contactEmail;
private final String contactName;
private final String website;
private final String vendor;
private final String product;
private final String web;
private final ZonedDateTime created;
private final ZonedDateTime modified;
private final boolean deleted;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
private String license;
private String name;
private String contactEmail;
private String contactName;
private String website;
private String vendor;
private String product;
private String web;
private ZonedDateTime created;
private ZonedDateTime modified;
private boolean deleted;
}

60
oparl-server/src/main/java/de/twomartens/oparlservice/repository/SystemRepository.java

@ -1,65 +1,9 @@
package de.twomartens.oparlservice.repository;
import de.twomartens.oparlservice.entity.internal.System;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import java.util.Optional;
@Repository
public class SystemRepository implements CrudRepository<System, Integer> {
@Override
public <S extends System> S save(S entity) {
return null;
}
@Override
public <S extends System> Iterable<S> saveAll(Iterable<S> entities) {
return null;
}
@Override
public Optional<System> findById(Integer integer) {
return Optional.empty();
}
@Override
public boolean existsById(Integer integer) {
return false;
}
@Override
public Iterable<System> findAll() {
return null;
}
@Override
public Iterable<System> findAllById(Iterable<Integer> integers) {
return null;
}
@Override
public long count() {
return 0;
}
@Override
public void deleteById(Integer integer) {
}
@Override
public void delete(System entity) {
}
@Override
public void deleteAll(Iterable<? extends System> entities) {
}
@Override
public void deleteAll() {
}
public interface SystemRepository extends JpaRepository<System, Integer> {
}

47
oparl-server/src/main/java/de/twomartens/oparlservice/service/OParlService.java

@ -1,14 +1,14 @@
package de.twomartens.oparlservice.service;
import de.twomartens.oparlservice.configs.OParlServiceProperties;
import de.twomartens.oparlservice.entity.dto.*;
import de.twomartens.oparlservice.entity.dto.System;
import de.twomartens.oparlservice.entity.dto.*;
import de.twomartens.oparlservice.repository.SystemRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.ZonedDateTime;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.stream.StreamSupport;
@ -18,8 +18,8 @@ public class OParlService {
private final OParlServiceProperties properties;
private final SystemRepository systemRepository;
public OParlService(OParlServiceProperties properties,
SystemRepository systemRepository) {
@Autowired
public OParlService(OParlServiceProperties properties, SystemRepository systemRepository) {
this.properties = properties;
this.systemRepository = systemRepository;
}
@ -122,27 +122,38 @@ public class OParlService {
public System getSystem() {
Iterable<de.twomartens.oparlservice.entity.internal.System> systems = systemRepository.findAll();
de.twomartens.oparlservice.entity.internal.System firstNotDeletedSystem = StreamSupport
Optional<de.twomartens.oparlservice.entity.internal.System> firstNotDeletedSystem = StreamSupport
.stream(systems.spliterator(), false)
.filter(system -> !system.isDeleted())
.findFirst().orElseThrow();
.findFirst();
de.twomartens.oparlservice.entity.internal.System system;
if (firstNotDeletedSystem.isEmpty()) {
de.twomartens.oparlservice.entity.internal.System newSystem = new de.twomartens.oparlservice.entity.internal.System();
newSystem.setCreated(ZonedDateTime.now());
newSystem.setModified(ZonedDateTime.now());
newSystem.setDeleted(false);
system = systemRepository.saveAndFlush(newSystem);
} else {
system = firstNotDeletedSystem.get();
}
return System.builder()
.id(String.valueOf(firstNotDeletedSystem.getId()))
.id(String.valueOf(system.getId()))
.type("https://schema.oparl.org/1.1/Schema")
.created(firstNotDeletedSystem.getCreated())
.modified(firstNotDeletedSystem.getModified())
.created(system.getCreated())
.modified(system.getModified())
.oparlVersion("https://schema.oparl.org/1.1/")
.body(properties.getUrl() + "/bodies")
.license(firstNotDeletedSystem.getLicense())
.name(firstNotDeletedSystem.getName())
.contactEmail(firstNotDeletedSystem.getContactEmail())
.contactName(firstNotDeletedSystem.getContactName())
.deleted(firstNotDeletedSystem.isDeleted())
.product(firstNotDeletedSystem.getProduct())
.vendor(firstNotDeletedSystem.getVendor())
.web(firstNotDeletedSystem.getWeb())
.website(firstNotDeletedSystem.getWebsite())
.license(system.getLicense())
.name(system.getName())
.contactEmail(system.getContactEmail())
.contactName(system.getContactName())
.deleted(system.isDeleted())
.product(system.getProduct())
.vendor(system.getVendor())
.web(system.getWeb())
.website(system.getWebsite())
.otherOparlVersions(Collections.emptyList())
.build();
}

Loading…
Cancel
Save