Skip to content

Commit

Permalink
Feature/packages and fileservice (#176)
Browse files Browse the repository at this point in the history
* delete url attribute

* add models for ImplementationPackage

* add implementation package

* add repository and services

* add dtos and copyright

* fix wiring

* add GET methods for implementation package

* implement POST

* implement GET

* add update and delete for implementation packages

* file: implementation dependency switched to implementation package

* fix merging errors

* use file instead of files

(one-to-one mapping from implementationPackage to file)

* minor fix

* implement create of file service

* make ImplementationPackage non-abstract

* fix: avoid strange model mapper behaviour

* implement POST and DELETE for a file of an ImplementationPackage

* delete PUT method because we currently do not implement this operation

* implement get Content (download) of file

* allow to load up file with the same name for different implementation packages

* rename defaultfile to file + join implementation package tables

* adapt exception message

* add implementation package service tests

* fix one to one mapping between implementation package and file

* add file service tests and fix deletion of file

* add check for NPE, fix controller tests

* controller tests for implementation packages

* fix FileServiceCloudStorageServiceTest

* don't store a foreign key in the file table

delete unused upload/download methods

* avoid IO exception caused by unclosed streamwriter

* take foreign key constraint into account when deleting a file

* adjust test to change in last commit

* remove dependency from File to ImplementationPackage

Co-authored-by: Manuela Weigold <manuela.weigold@iaas.uni-stuttgart.de>
  • Loading branch information
salmma and Manuela Weigold authored Dec 2, 2020
1 parent 5a89f9a commit c046e13
Show file tree
Hide file tree
Showing 38 changed files with 2,427 additions and 743 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
/*******************************************************************************
* Copyright (c) 2020 the qc-atlas contributors.
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* 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 org.planqk.atlas.core;

import org.springframework.context.annotation.Bean;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
/*******************************************************************************
* Copyright (c) 2020 the qc-atlas contributors.
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* 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 org.planqk.atlas.core.exceptions;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
/*******************************************************************************
* Copyright (c) 2020 the qc-atlas contributors.
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* 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 org.planqk.atlas.core.model;

import javax.persistence.Column;
Expand All @@ -21,5 +40,4 @@ public class File extends KnowledgeArtifact {

@Column(unique = true)
private String fileURL;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*******************************************************************************
* Copyright (c) 2020 the qc-atlas contributors.
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* 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 org.planqk.atlas.core.model;

import javax.persistence.Entity;

@Entity
public class FileImplementationPackage extends ImplementationPackage {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*******************************************************************************
* Copyright (c) 2020 the qc-atlas contributors.
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* 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 org.planqk.atlas.core.model;

import javax.persistence.Entity;

@Entity
public class FunctionImplementationPackage extends ImplementationPackage {

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

package org.planqk.atlas.core.model;

import java.net.URL;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
Expand Down Expand Up @@ -57,8 +56,6 @@ public class Implementation extends KnowledgeArtifact {

private String parameter;

private URL link;

private String dependencies;

private String version;
Expand All @@ -78,8 +75,8 @@ public class Implementation extends KnowledgeArtifact {

@ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
@JoinTable(name = "implementation_publication",
joinColumns = @JoinColumn(name = "implementation_id"),
inverseJoinColumns = @JoinColumn(name = "publication_id")
joinColumns = @JoinColumn(name = "implementation_id"),
inverseJoinColumns = @JoinColumn(name = "publication_id")
)
@EqualsAndHashCode.Exclude
@ToString.Exclude
Expand All @@ -92,37 +89,35 @@ public class Implementation extends KnowledgeArtifact {

@ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
@JoinTable(name = "implementation_tag",
joinColumns = @JoinColumn(name = "implementation_id"),
inverseJoinColumns = @JoinColumn(name = "tag_value"))
joinColumns = @JoinColumn(name = "implementation_id"),
inverseJoinColumns = @JoinColumn(name = "tag_value"))
@EqualsAndHashCode.Exclude
@ToString.Exclude
private Set<Tag> tags = new HashSet<>();

@EqualsAndHashCode.Exclude
@OneToMany(cascade = CascadeType.ALL,
mappedBy = "implementation",
orphanRemoval = true)
mappedBy = "implementation",
orphanRemoval = true)
private Set<ComputeResourceProperty> requiredComputeResourceProperties = new HashSet<>();

@ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
@JoinTable(name = "implementation_software_platforms",
joinColumns = @JoinColumn(name = "implementation_id"),
inverseJoinColumns = @JoinColumn(name = "software_platform_id")
joinColumns = @JoinColumn(name = "implementation_id"),
inverseJoinColumns = @JoinColumn(name = "software_platform_id")
)

@EqualsAndHashCode.Exclude
@ToString.Exclude
private Set<SoftwarePlatform> softwarePlatforms = new HashSet<>();


@OneToMany(mappedBy = "implementation",
cascade = CascadeType.ALL,
orphanRemoval = true)
@EqualsAndHashCode.Exclude
@OneToMany(cascade = CascadeType.ALL,
orphanRemoval = true)
@JoinTable(
name = "ImplementationFiles",
joinColumns = @JoinColumn(name = "implementation_id"),
inverseJoinColumns = @JoinColumn(name = "file_id")
)
private Set<File> files = new HashSet<>();
@ToString.Exclude
private Set<ImplementationPackage> implementationPackages = new HashSet<>();

public void addTag(@NonNull Tag tag) {
if (tags.contains(tag)) {
Expand Down Expand Up @@ -171,4 +166,20 @@ public void removeSoftwarePlatform(@NonNull SoftwarePlatform softwarePlatform) {
softwarePlatforms.remove(softwarePlatform);
softwarePlatform.removeImplementation(this);
}

public void addImplementationPackage(@NonNull ImplementationPackage implementationPackage) {
if (implementationPackages.contains(implementationPackage)) {
return;
}
this.implementationPackages.add(implementationPackage);
implementationPackage.setImplementation(this);
}

public void removeImplementationPackage(@NonNull ImplementationPackage implementationPackage) {
if (!implementationPackages.contains(implementationPackage)) {
return;
}
this.implementationPackages.remove(implementationPackage);
implementationPackage.setImplementation(null);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*******************************************************************************
* Copyright (c) 2020 the qc-atlas contributors.
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* 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 org.planqk.atlas.core.model;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

@Entity
@NoArgsConstructor
@EqualsAndHashCode(callSuper = true)
@Data
public class ImplementationPackage extends HasId {

private String name;

private String description;

private ImplementationPackageType packageType;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "implementation_id")
private Implementation implementation;

@OneToOne(fetch = FetchType.LAZY, orphanRemoval = true)
@EqualsAndHashCode.Exclude
@JoinTable(
name = "ImplementationPackageFile",
joinColumns = @JoinColumn(name = "implementation_package_id"),
inverseJoinColumns = @JoinColumn(name = "file_id")
)
private File file;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*******************************************************************************
* Copyright (c) 2020 the qc-atlas contributors.
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* 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 org.planqk.atlas.core.model;

public enum ImplementationPackageType {
FILE, TOSCA, FUNCTION
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*******************************************************************************
* Copyright (c) 2020 the qc-atlas contributors.
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* 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 org.planqk.atlas.core.model;

import javax.persistence.Entity;

@Entity
public class TOSCAImplementationPackage extends ImplementationPackage {

}
Original file line number Diff line number Diff line change
@@ -1,27 +1,41 @@
/*******************************************************************************
* Copyright (c) 2020 the qc-atlas contributors.
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* 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 org.planqk.atlas.core.repository;

import java.util.Optional;
import java.util.UUID;

import org.planqk.atlas.core.model.File;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

@Repository
public interface FileRepository extends JpaRepository<File, UUID> {

Optional<File> findByFileURL(String fileURL);

@Query(value = "SELECT * " +
"FROM file " +
"INNER JOIN implementation_files on file.id = implementation_files.file_id " +
"INNER JOIN implementation_package_file on file.id = implementation_package_file.file_id " +
"INNER JOIN knowledge_artifact ka on file.id = ka.id " +
"WHERE implementation_files.implementation_id = :implId",
"WHERE implementation_package_file.implementation_package_id = :implementationPackageId",
nativeQuery = true)
Page<File> findFilesByImplementation(@Param("implId") UUID implementationId, Pageable pageable);
Optional<File> findByImplementationPackage_Id(@Param("implementationPackageId") UUID implementationPackageId);
}

Loading

0 comments on commit c046e13

Please sign in to comment.