Skip to content

Commit

Permalink
feat(SPDX): Use new SPDX library (eclipse-sw360#1496) and release pag…
Browse files Browse the repository at this point in the history
…es for showing SPDX/SPDX Lite data (eclipse-sw360#1240)
  • Loading branch information
tuannn2 committed Apr 28, 2022
2 parents b97fd7f + e6fd4a5 commit 2daca6e
Show file tree
Hide file tree
Showing 21 changed files with 861 additions and 363 deletions.
48 changes: 23 additions & 25 deletions .github/workflows/githubactions.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
# -----------------------------------------------------------------------------
# Copyright Siemens AG, 2021.
# Part of the SW360 Portal Project.
#
# This program and the accompanying materials are made
# available under the terms of the Eclipse Public License 2.0
# which is available at https://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
#
# -----------------------------------------------------------------------------
name: SW360

name: SW360

on:
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
branches: [ dev/feature-edit_and_clone_obligation ]

#UTC
schedule:
- cron: '0 0 * * *'

env:
COUCHDB_USER: admin
Expand All @@ -28,11 +18,7 @@ jobs:

steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v2
with:
java-version: '11'
distribution: 'adopt'

- name: Setup CouchDB
uses: iamssen/couchdb-github-action@master
with:
Expand All @@ -46,10 +32,22 @@ jobs:
sudo mkdir /etc/sw360
sudo cp ./scripts/sw360BackendRestDockerConfig/etc_sw360/couchdb-test.properties /etc/sw360/
- name: Verify license headers
- name: Check property file
run: cat build-configuration/test-resources/couchdb-test.properties

- name: Test endpoint
run: |
chmod +x .github/testForLicenseHeaders.sh
bash .github/testForLicenseHeaders.sh
curl -f http://127.0.0.1:5984/
- name: Test auth
run: |
curl -X POST -H "Content-Type: application/json; charset=utf-8" -d '{"name": "${COUCHDB_USER}", "password": "${COUCHDB_PASSWORD}"}' http://127.0.0.1:5984/_session
- name: Set up JDK 11
uses: actions/setup-java@v2
with:
java-version: '11'
distribution: 'adopt'

- name: Install Thrift and mkdocs
run: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.eclipse.sw360.datahandler.thrift.changelogs.ChangedFields;
import org.eclipse.sw360.datahandler.thrift.changelogs.Operation;
import org.eclipse.sw360.datahandler.thrift.users.User;
import org.eclipse.sw360.datahandler.thrift.RequestStatus;

import com.cloudant.client.api.CloudantClient;
import com.google.common.collect.ImmutableSet;
Expand Down Expand Up @@ -69,6 +70,17 @@ public ChangeLogs getChangeLogsById(String id) throws SW360Exception {
return changeLogs;
}

public RequestStatus deleteChangeLogsByDocumentId(String docId, User user) {
try {
for (ChangeLogs changeLog: getChangeLogsByDocumentId(user, docId)) {
changeLogsRepository.remove(changeLog);
}
return RequestStatus.SUCCESS;
} catch (Exception e) {
return RequestStatus.FAILURE;
}
}

private ChangeLogs removeNullToEmtpyChanges(ChangeLogs changeLog) {
Set<ChangedFields> changes = changeLog.getChanges();
if (CommonUtils.isNotEmpty(changes)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.eclipse.sw360.datahandler.thrift.changelogs.ChangeLogs;
import org.eclipse.sw360.datahandler.thrift.changelogs.ChangeLogsService;
import org.eclipse.sw360.datahandler.thrift.users.User;
import org.eclipse.sw360.datahandler.thrift.RequestStatus;

import com.cloudant.client.api.CloudantClient;

Expand Down Expand Up @@ -56,4 +57,11 @@ public ChangeLogs getChangeLogsById(String id) throws SW360Exception {
assertNotEmpty(id);
return handler.getChangeLogsById(id);
}

@Override
public RequestStatus deleteChangeLogsByDocumentId(String docId, User user) throws SW360Exception {
assertNotEmpty(docId);
assertUser(user);
return handler.deleteChangeLogsByDocumentId(docId, user);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -356,4 +356,14 @@ public List<ObligationElement> searchObligationElement(String text) throws TExce
return searchHandler.search(text);
}

@Override
public String convertTextToNode(Obligation obligation, User user) throws TException {
String node= handler.convertTextToNodes(obligation,user);
return node;
}

@Override
public String updateObligation(Obligation oblig, User user) throws TException {
return handler.updateObligation(oblig, user);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*/
package org.eclipse.sw360.licenses.db;

import org.apache.xmlbeans.impl.xb.xsdschema.Attribute;
import org.eclipse.sw360.components.summary.SummaryType;
import org.eclipse.sw360.datahandler.cloudantclient.DatabaseConnectorCloudant;
import org.eclipse.sw360.datahandler.cloudantclient.DatabaseRepositoryCloudantClient;
Expand Down Expand Up @@ -39,6 +40,7 @@
import com.cloudant.client.api.CloudantClient;
import com.cloudant.client.api.model.Response;
import com.google.common.collect.Sets;
import static com.google.common.base.Strings.isNullOrEmpty;

import java.net.MalformedURLException;
import java.sql.Timestamp;
Expand All @@ -54,6 +56,11 @@

import com.liferay.portal.kernel.json.JSONFactoryUtil;
import com.liferay.portal.kernel.json.JSONArray;
import org.eclipse.sw360.datahandler.db.DatabaseHandlerUtil;
import org.eclipse.sw360.datahandler.thrift.changelogs.Operation;
import com.google.common.collect.Lists;
import org.eclipse.sw360.datahandler.common.DatabaseSettings;

/**
* Class for accessing the CouchDB database
*
Expand All @@ -77,6 +84,7 @@ public class LicenseDatabaseHandler {
private final LicenseModerator moderator;
private final CustomPropertiesRepository customPropertiesRepository;
private final DatabaseRepositoryCloudantClient[] repositories;
private DatabaseHandlerUtil dbHandlerUtil;

private static boolean IMPORT_STATUS = false;
private static long IMPORT_TIME = 0;
Expand All @@ -87,6 +95,8 @@ public class LicenseDatabaseHandler {
public LicenseDatabaseHandler(Supplier<CloudantClient> httpClient, String dbName) throws MalformedURLException {
// Create the connector
db = new DatabaseConnectorCloudant(httpClient, dbName);
DatabaseConnectorCloudant dbChangelogs = new DatabaseConnectorCloudant(httpClient, DatabaseSettings.COUCH_DB_CHANGE_LOGS);
dbHandlerUtil = new DatabaseHandlerUtil(dbChangelogs);

// Create the repository
licenseRepository = new LicenseRepository(db);
Expand Down Expand Up @@ -217,11 +227,43 @@ public String addObligations(@NotNull Obligation obligs, User user) throws SW360
return null;
}
prepareTodo(obligs);
List<Obligation> obligations = getObligations();
for (Obligation obligation : obligations) {
if (obligation.getTitle().equals(obligs.getTitle())) {
log.error("An Obligation with the same title already exists.");
return null;
}
}
obligRepository.add(obligs);
obligs.setNode(null);
Obligation obligTmp = new Obligation();
obligTmp.setDevelopment(false)
.setDistribution(false)
.setId(obligs.getId());
dbHandlerUtil.addChangeLogs(obligs, obligTmp, user.getEmail(), Operation.CREATE, null, Lists.newArrayList(), null, null);

return obligs.getId();
}

/**
* Update a existed obligation to the database.
*
* @return ID of the added obligations.
*/
public String updateObligation(@NotNull Obligation oblig, User user) throws SW360Exception {
if (!PermissionUtils.isUserAtLeast(UserGroup.CLEARING_ADMIN, user)){
return null;
}
Obligation oldObligation = getObligationsById(oblig.getId());
prepareTodo(oblig);
obligRepository.update(oblig);
oblig.setNode(null);
oldObligation.setNode(null);
dbHandlerUtil.addChangeLogs(oblig, oldObligation, user.getEmail(), Operation.UPDATE, null, Lists.newArrayList(), null, null);

return oblig.getId();
}

/**
* Adds a new obligation element to the database.
*
Expand Down Expand Up @@ -756,6 +798,16 @@ private List<ObligationElement> isExistedObligationElement(ObligationElement obl
if (existedObligationElement.isEmpty()) {
return Collections.emptyList();
}

if (isNullOrEmpty(lang) || isNullOrEmpty(action) || isNullOrEmpty(object)) {
log.info("Obligation Element have empty field");
List<ObligationElement> existedElement = existedObligationElement.stream().filter(el -> lang.equals(el.getLangElement()) && action.equals(el.getAction()) && object.equals(el.getObject())).collect(Collectors.toList());
if (CommonUtils.isNullOrEmptyCollection(existedElement)) {
return Collections.emptyList();
} else {
return existedElement;
}
}
return existedObligationElement;
}

Expand Down Expand Up @@ -938,6 +990,12 @@ public RequestSummary importAllOSADLLicenses(User user) {
return requestSummary;
}

public String convertTextToNodes(Obligation obligation, User user) throws SW360Exception {
OSADLObligationConnector osadlConnector = new OSADLObligationConnector();
String obligNode = addNodes(osadlConnector.parseText(obligation.getText()), user);
return obligNode;
}

public RequestStatus deleteObligations(String id, User user) throws SW360Exception {
Obligation oblig = obligRepository.get(id);
assertNotNull(oblig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public class ErrorMessages {
public static final String ERROR_GETTING_CLEARING_REQUEST = "Error fetching clearing request from backend.";
public static final String LICENSE_TYPE_DUPLICATE = "This license type already exists.";
public static final String LICENSE_TYPE_ACCESS_DENIED = "User does not have the permission to add license type.";
public static final String OBLIGATION_NOT_ADDED = "Obligation could not be added.";
public static final String OBLIGATION_NOT_UPDATED = "Obligation could not be updated.";

//this map is used in errorKeyToMessage.jspf to generate key-value pairs for the liferay-ui error tag
public static final ImmutableList<String> allErrorMessages = ImmutableList.<String>builder()
Expand Down Expand Up @@ -109,6 +111,8 @@ public class ErrorMessages {
.add(ERROR_USER_CREATE)
.add(ERROR_USER_UPDATE)
.add(ERROR_USER_ACTIVATE_DEACTIVATE)
.add(OBLIGATION_NOT_ADDED)
.add(OBLIGATION_NOT_UPDATED)
.build();

private ErrorMessages() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ public class PortalConstants {
public static final String LOAD_OBLIGATIONS_EDIT = "load_obligations_edit";
public static final String LOAD_LICENSE_OBLIGATIONS = "load_license_obligations";
public static final String UNUSED_RELEASES = "unusedReleases";
public static final String OBLIGATION_EDIT = "obligationEdit";
public static final String OBLIGATION_CHANGELOG = "obligation_changelog";

//! Specialized keys for license types
public static final String LICENSE_TYPE_LIST = "licenseTypeList";
Expand Down
Loading

0 comments on commit 2daca6e

Please sign in to comment.