Skip to content

Commit

Permalink
feat(ECC):Added pagination to ECC release list
Browse files Browse the repository at this point in the history
  • Loading branch information
eldrin30 committed Jun 14, 2023
1 parent e1d2cb2 commit 4101849
Show file tree
Hide file tree
Showing 7 changed files with 337 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1972,6 +1972,10 @@ public List<Release> getAccessibleReleases(Set<String> ids, User user) {
return getAccessibleReleaseList(releaseRepository.makeSummary(SummaryType.SHORT, ids), user);
}

public Map<PaginationData, List<Release>> getAccessibleReleasesWithPagination(User user, PaginationData pageData) throws TException {
return releaseRepository.getAccessibleReleasesWithPagination(user, pageData);
}

private List<Release> getAccessibleReleaseList(List<Release> releaseList, User user) {
List<Release> resultList = new ArrayList<Release>();
for (Release release : releaseList) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.eclipse.sw360.datahandler.couchdb.SummaryAwareRepository;
import org.eclipse.sw360.datahandler.thrift.components.Release;
import org.eclipse.sw360.datahandler.thrift.users.User;
import org.eclipse.sw360.datahandler.thrift.PaginationData;

import java.util.*;
import com.cloudant.client.api.model.DesignDocument.MapReduce;
Expand All @@ -27,6 +28,11 @@

import static com.google.common.base.Strings.isNullOrEmpty;

import com.google.common.collect.Maps;
import com.google.common.collect.Lists;
import com.cloudant.client.api.views.ViewRequest;
import com.cloudant.client.api.views.ViewResponse;

/**
* CRUD access for the Release class
*
Expand Down Expand Up @@ -126,6 +132,40 @@ public class ReleaseRepository extends SummaryAwareRepository<Release> {
" emit(doc.version.toLowerCase(), doc._id);" +
" } " +
"}";
private static final String BY_STATUS_VIEW =
"function(doc) {" +
" if (doc.type == 'release') {" +
" emit(doc.eccInformation.eccStatus, doc._id);" +
" } " +
"}";

private static final String BY_ASSESSOR_CONTACT_PERSON_VIEW =
"function(doc) {" +
" if (doc.type == 'release') {" +
" emit(doc.eccInformation.assessorContactPerson, doc._id);" +
" } " +
"}";

private static final String BY_ASSESSOR_DEPARTMENT_VIEW =
"function(doc) {" +
" if (doc.type == 'release') {" +
" emit(doc.eccInformation.assessorDepartment, doc._id);" +
" } " +
"}";

private static final String BY_ASSESSMENT_DATE_VIEW =
"function(doc) {" +
" if (doc.type == 'release') {" +
" emit(doc.eccInformation.assessmentDate, doc._id);" +
" } " +
"}";

private static final String BY_CREATOR_DEPARTMENT_VIEW =
"function(doc) {" +
" if (doc.type == 'release') {" +
" emit(doc.creatorDepartment, doc._id);" +
" } " +
"}";

public ReleaseRepository(DatabaseConnectorCloudant db, VendorRepository vendorRepository) {
super(Release.class, db, new ReleaseSummary(vendorRepository));
Expand All @@ -144,6 +184,11 @@ public ReleaseRepository(DatabaseConnectorCloudant db, VendorRepository vendorRe
views.put("releaseByName", createMapReduce(BY_LOWERCASE_RELEASE_NAME_VIEW, null));
views.put("releaseByVersion", createMapReduce(BY_LOWERCASE_RELEASE_VERSION_VIEW, null));
views.put("releaseIdsByVendorId", createMapReduce(RELEASEIDSBYVENDORID, null));
views.put("byStatus", createMapReduce(BY_STATUS_VIEW, null));
views.put("byECCAssessorContactPerson", createMapReduce(BY_ASSESSOR_CONTACT_PERSON_VIEW, null));
views.put("byECCAssessorGroup", createMapReduce(BY_ASSESSOR_DEPARTMENT_VIEW, null));
views.put("byECCAssessmentDate", createMapReduce(BY_ASSESSMENT_DATE_VIEW, null));
views.put("byCreatorGroup", createMapReduce(BY_CREATOR_DEPARTMENT_VIEW, null));
initStandardDesignDocument(views, db);
}

Expand Down Expand Up @@ -256,4 +301,69 @@ public Set<Release> searchByExternalIds(Map<String, Set<String>> externalIds) {
public List<Release> getReferencingReleases(String releaseId) {
return queryView("usedInReleaseRelation", releaseId);
}

public Map<PaginationData, List<Release>> getAccessibleReleasesWithPagination(User user, PaginationData pageData) {
final int rowsPerPage = pageData.getRowsPerPage();
Map<PaginationData, List<Release>> result = Maps.newHashMap();
List<Release> releases = Lists.newArrayList();
final boolean ascending = pageData.isAscending();
final int sortColumnNo = pageData.getSortColumnNumber();

ViewRequestBuilder query;
switch (sortColumnNo) {
case -1:
query = getConnector().createQuery(Release.class, "byCreatedOn");
break;
case 0:
query = getConnector().createQuery(Release.class, "byStatus");
break;
case 1:
query = getConnector().createQuery(Release.class, "byname");
break;
case 2:
query = getConnector().createQuery(Release.class, "releaseByVersion");
break;
case 3:
query = getConnector().createQuery(Release.class, "byCreatorGroup");
break;
case 4:
query = getConnector().createQuery(Release.class, "byECCAssessorContactPerson");
break;
case 5:
query = getConnector().createQuery(Release.class, "byECCAssessorGroup");
break;
case 6:
query = getConnector().createQuery(Release.class, "byECCAssessmentDate");
break;
default:
query = getConnector().createQuery(Release.class, "all");
break;
}

ViewRequest<String, Object> request = null;
if (rowsPerPage == -1) {
request = query.newRequest(Key.Type.STRING, Object.class).descending(!ascending).includeDocs(true).build();
} else {
request = query.newPaginatedRequest(Key.Type.STRING, Object.class).rowsPerPage(rowsPerPage)
.descending(!ascending).includeDocs(true).build();
}

ViewResponse<String, Object> response = null;
try {
response = request.getResponse();
int pageNo = pageData.getDisplayStart() / rowsPerPage;
int i = 1;
while (i <= pageNo) {
response = response.nextPage();
i++;
}
releases = response.getDocsAs(Release.class);
} catch (Exception e) {
log.error("Error getting recent releases", e);
}
releases = makeSummaryWithPermissionsFromFullDocs(SummaryType.SUMMARY, releases, user);
pageData.setTotalRowCount(response.getTotalRowCount());
result.put(pageData, releases);
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ public List<Release> getAccessibleReleaseSummary(User user) throws TException {
return handler.getAccessibleReleaseSummary(user);
}

@Override
public Map<PaginationData, List<Release>> getAccessibleReleasesWithPagination(User user, PaginationData pageData) throws TException {
assertUser(user);
return handler.getAccessibleReleasesWithPagination(user, pageData);
}

@Override
public List<Component> refineSearch(String text, Map<String, Set<String>> subQueryRestrictions) throws TException {
return componentSearchHandler.search(text, subQueryRestrictions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,7 @@ public class PortalConstants {
public static final String UNSUBSCRIBE = "unsubscribe";
public static final String UNSUBSCRIBE_RELEASE = "unsubscribe_release";
public static final String LOAD_COMPONENT_LIST = "load_component_list";
public static final String LOAD_ECC_LIST = "load_ecc_list";

// fossology actions
public static final String FOSSOLOGY_PREFIX = "fossology";
Expand Down
Loading

0 comments on commit 4101849

Please sign in to comment.