diff --git a/src/main/java/net/geant/nmaas/portal/api/domain/ApplicationBaseS.java b/src/main/java/net/geant/nmaas/portal/api/domain/ApplicationBaseS.java
new file mode 100644
index 0000000000000000000000000000000000000000..8239b7a5dcc4142663c1f35c01b92fcf393ef23c
--- /dev/null
+++ b/src/main/java/net/geant/nmaas/portal/api/domain/ApplicationBaseS.java
@@ -0,0 +1,17 @@
+package net.geant.nmaas.portal.api.domain;
+
+import net.geant.nmaas.portal.persistent.entity.AppDescription;
+import net.geant.nmaas.portal.persistent.entity.Tag;
+
+import java.util.List;
+import java.util.Set;
+
+public interface ApplicationBaseS {
+ Long getId();
+ String getName();
+
+ List<AppDescription> getDescriptions();
+
+ Set<Tag> getTags();
+}
+
diff --git a/src/main/java/net/geant/nmaas/portal/api/domain/ApplicationBaseViewS.java b/src/main/java/net/geant/nmaas/portal/api/domain/ApplicationBaseViewS.java
index 5f42d1d06e19b49108cf78fc16dd1c0dab126916..85eefdc940e0b9f0d7b6155586159763513c4f41 100644
--- a/src/main/java/net/geant/nmaas/portal/api/domain/ApplicationBaseViewS.java
+++ b/src/main/java/net/geant/nmaas/portal/api/domain/ApplicationBaseViewS.java
@@ -2,6 +2,8 @@ package net.geant.nmaas.portal.api.domain;
import lombok.*;
import lombok.experimental.SuperBuilder;
+import net.geant.nmaas.portal.persistent.entity.AppDescription;
+import net.geant.nmaas.portal.persistent.entity.Tag;
import javax.validation.constraints.NotEmpty;
import java.util.ArrayList;
diff --git a/src/main/java/net/geant/nmaas/portal/api/market/ApplicationController.java b/src/main/java/net/geant/nmaas/portal/api/market/ApplicationController.java
index 95c5d9fe160b71e658b316ab3970cd1ed4ff5947..75dd1449095a3ade806646aff1ba8c823dfe0a5b 100644
--- a/src/main/java/net/geant/nmaas/portal/api/market/ApplicationController.java
+++ b/src/main/java/net/geant/nmaas/portal/api/market/ApplicationController.java
@@ -90,7 +90,7 @@ public class ApplicationController extends AppBaseController {
@GetMapping("/base")
@Transactional
public List<ApplicationBaseViewS> getAllActiveApplicationBase() {
- return appBaseService.findAllActiveApps().stream()
+ return appBaseService.findAllActiveAppsSmall().stream()
.map(app -> modelMapper.map(app, ApplicationBaseViewS.class))
.map(this::setAppRating)
.collect(Collectors.toList());
diff --git a/src/main/java/net/geant/nmaas/portal/persistent/entity/ApplicationBase.java b/src/main/java/net/geant/nmaas/portal/persistent/entity/ApplicationBase.java
index be0f31d721f58a922331acb5427eda9971e905fc..98d7dc7f9935cd5f0415f091febe3edb2c618e41 100644
--- a/src/main/java/net/geant/nmaas/portal/persistent/entity/ApplicationBase.java
+++ b/src/main/java/net/geant/nmaas/portal/persistent/entity/ApplicationBase.java
@@ -5,9 +5,21 @@ import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
+import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
-import javax.persistence.*;
+import javax.persistence.CascadeType;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.JoinTable;
+import javax.persistence.ManyToMany;
+import javax.persistence.OneToMany;
+import javax.persistence.OneToOne;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashSet;
@@ -63,16 +75,23 @@ public class ApplicationBase implements Serializable {
@OneToMany(orphanRemoval = true, fetch = FetchType.LAZY, cascade = CascadeType.ALL)
private Set<ApplicationVersion> versions = new HashSet<>();
- public ApplicationBase(String name){
+ public ApplicationBase(String name) {
this.name = name;
}
- public ApplicationBase(Long id, String name){
+ public ApplicationBase(Long id, String name) {
this(name);
this.id = id;
}
- public void validate(){
+ public ApplicationBase(long id, String name, Set<Tag> tags, List<AppDescription> descriptions) {
+ this(name);
+ this.id = id;
+ this.tags = tags;
+ this.descriptions = descriptions;
+ }
+
+ public void validate() {
checkArgument(StringUtils.isNotEmpty(name), "App must have name");
checkArgument(name.matches("^[a-zA-Z0-9- ]+$"), "Name contains illegal characters");
checkArgument(descriptions != null && !descriptions.isEmpty(), "Descriptions cannot be null or empty");
diff --git a/src/main/java/net/geant/nmaas/portal/persistent/repositories/ApplicationBaseRepository.java b/src/main/java/net/geant/nmaas/portal/persistent/repositories/ApplicationBaseRepository.java
index 144f78c2175371dc7b62a285bc3427133c21f585..f14232e7fc6caa5920598c147ed8a6f231a228fb 100644
--- a/src/main/java/net/geant/nmaas/portal/persistent/repositories/ApplicationBaseRepository.java
+++ b/src/main/java/net/geant/nmaas/portal/persistent/repositories/ApplicationBaseRepository.java
@@ -1,12 +1,14 @@
package net.geant.nmaas.portal.persistent.repositories;
-import java.util.List;
-import java.util.Optional;
+import net.geant.nmaas.portal.api.domain.ApplicationBaseS;
import net.geant.nmaas.portal.persistent.entity.ApplicationBase;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
+import java.util.List;
+import java.util.Optional;
+
@Repository
public interface ApplicationBaseRepository extends JpaRepository<ApplicationBase, Long> {
@@ -20,4 +22,11 @@ public interface ApplicationBaseRepository extends JpaRepository<ApplicationBase
@Query("select count(distinct ab.name) FROM ApplicationBase ab JOIN Application a on a.name = ab.name WHERE a.state = 'ACTIVE'")
long countAllActive();
+// @Query(value = "select new net.geant.nmaas.portal.api.domain.ApplicationBaseSTest(ab.id, ab.name, ab.tags) from ApplicationBase ab JOIN Application a ON a.name = ab.name " +
+// " WHERE a.state = 'ACTIVE' ", nativeQuery = true)
+// List<ApplicationBaseSTest> findAllSmallQuery();
+
+ @Query("Select ab from ApplicationBase ab JOIN ApplicationVersion av on av.appVersionId = ab.id WHERE av.state = 'ACTIVE'")
+ List<ApplicationBaseS> findAllSmall();
+
}
\ No newline at end of file
diff --git a/src/main/java/net/geant/nmaas/portal/service/ApplicationBaseService.java b/src/main/java/net/geant/nmaas/portal/service/ApplicationBaseService.java
index 77871894fdc297e27b3e6fe3a5868b975bd1a695..8df8c76cb250247843dedac345bc410ca32eb3ac 100644
--- a/src/main/java/net/geant/nmaas/portal/service/ApplicationBaseService.java
+++ b/src/main/java/net/geant/nmaas/portal/service/ApplicationBaseService.java
@@ -1,5 +1,7 @@
package net.geant.nmaas.portal.service;
+import net.geant.nmaas.portal.api.domain.ApplicationBaseS;
+import net.geant.nmaas.portal.api.domain.ApplicationBaseViewS;
import net.geant.nmaas.portal.persistent.entity.ApplicationBase;
import net.geant.nmaas.portal.persistent.entity.ApplicationState;
@@ -17,6 +19,8 @@ public interface ApplicationBaseService {
List<ApplicationBase> findAll();
List<ApplicationBase> findAllActiveApps();
+ List<ApplicationBaseS> findAllActiveAppsSmall();
+
ApplicationBase getBaseApp(Long id);
ApplicationBase findByName(String name);
diff --git a/src/main/java/net/geant/nmaas/portal/service/impl/ApplicationBaseServiceImpl.java b/src/main/java/net/geant/nmaas/portal/service/impl/ApplicationBaseServiceImpl.java
index 1ccf46895e78ff1f19b49a620aa3c471b493c0b1..93447679015cb39b50ee17287adf1915a9ff5e2c 100644
--- a/src/main/java/net/geant/nmaas/portal/service/impl/ApplicationBaseServiceImpl.java
+++ b/src/main/java/net/geant/nmaas/portal/service/impl/ApplicationBaseServiceImpl.java
@@ -2,6 +2,7 @@ package net.geant.nmaas.portal.service.impl;
import lombok.AllArgsConstructor;
import lombok.extern.log4j.Log4j2;
+import net.geant.nmaas.portal.api.domain.ApplicationBaseS;
import net.geant.nmaas.portal.api.exception.MissingElementException;
import net.geant.nmaas.portal.api.exception.ProcessingException;
import net.geant.nmaas.portal.events.ApplicationActivatedEvent;
@@ -81,7 +82,7 @@ public class ApplicationBaseServiceImpl implements ApplicationBaseService {
throw new ProcessingException("Updated entity id must not be null");
}
Optional<ApplicationBase> fromDb = appBaseRepository.findById(id);
- if(fromDb.isPresent()) {
+ if (fromDb.isPresent()) {
ApplicationBase base = fromDb.get();
base.setOwner(owner);
base.validate();
@@ -99,7 +100,7 @@ public class ApplicationBaseServiceImpl implements ApplicationBaseService {
.findAny()
.ifPresent(appVersion -> appVersion.setState(state));
appBase.validate();
- appBaseRepository.save(appBase);
+ appBaseRepository.save(appBase);
if (state.equals(ApplicationState.ACTIVE)) {
eventPublisher.publishEvent(new ApplicationActivatedEvent(this, name, version));
}
@@ -120,6 +121,10 @@ public class ApplicationBaseServiceImpl implements ApplicationBaseService {
.collect(Collectors.toList());
}
+ public List<ApplicationBaseS> findAllActiveAppsSmall() {
+ return appBaseRepository.findAllSmall();
+ }
+
@Override
public ApplicationBase getBaseApp(Long id) {
return appBaseRepository.findById(id)
@@ -154,12 +159,12 @@ public class ApplicationBaseServiceImpl implements ApplicationBaseService {
.filter(description -> description.getLanguage().equals("en"))
.findFirst().orElseThrow(() -> new IllegalStateException("English description is missing"));
app.getDescriptions().forEach(description -> {
- if (StringUtils.isEmpty(description.getBriefDescription())) {
- description.setBriefDescription(appDescription.getBriefDescription());
- }
- if (StringUtils.isEmpty(description.getFullDescription())) {
- description.setFullDescription(appDescription.getFullDescription());
- }
- });
+ if (StringUtils.isEmpty(description.getBriefDescription())) {
+ description.setBriefDescription(appDescription.getBriefDescription());
+ }
+ if (StringUtils.isEmpty(description.getFullDescription())) {
+ description.setFullDescription(appDescription.getFullDescription());
+ }
+ });
}
}