Skip to content

Commit 9452b2b

Browse files
GMishxsmrutis1
authored andcommitted
fix(cloudant): fix attachment creation
While creating attachment with repository.add(), there are additional steps needed to create the attachment in DB. Not used by API. Signed-off-by: Gaurav Mishra <mishra.gaurav@siemens.com>
1 parent 5bdef6d commit 9452b2b

File tree

18 files changed

+142
-49
lines changed

18 files changed

+142
-49
lines changed

backend/common/src/main/java/org/eclipse/sw360/datahandler/db/AttachmentDatabaseHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public AttachmentConnector getAttachmentConnector(){
6767
return attachmentConnector;
6868
}
6969

70-
public AttachmentContent add(AttachmentContent attachmentContent){
70+
public AttachmentContent add(AttachmentContent attachmentContent) throws SW360Exception {
7171
attachmentContentRepository.add(attachmentContent);
7272
return attachmentContent;
7373
}
@@ -138,7 +138,7 @@ public void deleteAttachmentUsagesByUsageDataTypes(Source usedBy, Set<UsageData.
138138
}
139139
}
140140

141-
public AttachmentUsage makeAttachmentUsage(AttachmentUsage attachmentUsage) {
141+
public AttachmentUsage makeAttachmentUsage(AttachmentUsage attachmentUsage) throws SW360Exception {
142142
attachmentUsageRepository.add(attachmentUsage);
143143
return attachmentUsage;
144144
}

backend/common/src/main/java/org/eclipse/sw360/datahandler/db/DatabaseHandlerUtil.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -625,10 +625,14 @@ private static <T extends TBase> Runnable prepareChangeLogRunnable(T newDocVersi
625625
referenceDocLogList.stream().forEach(referenceDocLog -> {
626626
referenceDocLog.setDocumentId(changeLogParentId);
627627
changelog.debug(convertObjectToJson(referenceDocLog));
628-
changeLogRepository.add(referenceDocLog);
628+
try {
629+
changeLogRepository.add(referenceDocLog);
630+
} catch (SW360Exception e) {
631+
log.error("Error occurred while adding change log", e);
632+
}
629633
});
630634
} catch (Exception exp) {
631-
log.error("Error occured while creating Change Logs", exp);
635+
log.error("Error occurred while creating Change Logs", exp);
632636
}
633637
};
634638
}

backend/common/src/main/java/org/eclipse/sw360/datahandler/db/ProjectDatabaseHandler.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1137,7 +1137,12 @@ public List<ProjectVulnerabilityRating> getProjectVulnerabilityRatingByProjectId
11371137
public RequestStatus updateProjectVulnerabilityRating(ProjectVulnerabilityRating link) {
11381138
if( ! link.isSetId()){
11391139
link.setId(SW360Constants.PROJECT_VULNERABILITY_RATING_ID_PREFIX + link.getProjectId());
1140-
pvrRepository.add(link);
1140+
try {
1141+
pvrRepository.add(link);
1142+
} catch (SW360Exception e) {
1143+
log.error("Unable to update project vulnerability rating.", e);
1144+
return RequestStatus.FAILURE;
1145+
}
11411146
} else {
11421147
pvrRepository.update(link);
11431148
}

backend/components/src/test/java/org/eclipse/sw360/components/db/BulkDeleteUtilTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,7 +1138,7 @@ public void checkDeletedReleaseListInLoop(int loopCount, List<Release> deletedRe
11381138
assertTrue(CommonUtils.isNullOrEmptyMap(relationShip_c1));
11391139
}
11401140

1141-
private void createTestRecords001() {
1141+
private void createTestRecords001() throws SW360Exception {
11421142

11431143
List<Component> components = new ArrayList<Component>();
11441144
Component component_dr_A = new Component().setId(COMPONENT_ID_A).setName("DR_A").setDescription("DR Component A").setCreatedBy(USER_EMAIL1).setMainLicenseIds(new HashSet<>(Arrays.asList("lic1"))).setCreatedOn("2022-07-20");
@@ -1208,7 +1208,7 @@ private void createTestRecords001() {
12081208
}
12091209

12101210

1211-
private void createTestRecords002() {
1211+
private void createTestRecords002() throws SW360Exception {
12121212

12131213
List<Component> components = new ArrayList<Component>();
12141214
Component component_dr_A = new Component().setId(COMPONENT_ID_A).setName("DR_A").setDescription("DR Component A").setCreatedBy(USER_EMAIL1).setMainLicenseIds(new HashSet<>(Arrays.asList("lic1"))).setCreatedOn("2022-07-20");
@@ -1300,7 +1300,7 @@ private void createTestRecords002() {
13001300
}
13011301
}
13021302

1303-
private void createTestRecords002(int maxLink, int depth, List<String> releaseIdList, List<String> componentIdList) {
1303+
private void createTestRecords002(int maxLink, int depth, List<String> releaseIdList, List<String> componentIdList) throws SW360Exception {
13041304
//create root node
13051305
String componentId = String.format("dr_%08x", treeNodeCreateReleaseCounter);
13061306
treeNodeCreateReleaseCounter++;
@@ -1323,7 +1323,7 @@ private void createTestRecords002(int maxLink, int depth, List<String> releaseId
13231323
createReleaseTree(releaseId, 0, releaseIdList, componentIdList);
13241324
}
13251325

1326-
private void createReleaseTree(String parentId, int level, List<String> outReleaseIdList, List< String> outComponentIdList) {
1326+
private void createReleaseTree(String parentId, int level, List<String> outReleaseIdList, List< String> outComponentIdList) throws SW360Exception {
13271327
//create a compoent
13281328
String componentId = String.format("dr_%08x", treeNodeCreateReleaseCounter);
13291329
treeNodeCreateReleaseCounter++;

backend/fossology/src/main/java/org/eclipse/sw360/fossology/config/FossologyRestConfig.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import org.apache.logging.log4j.LogManager;
1717
import org.apache.logging.log4j.Logger;
18+
import org.eclipse.sw360.datahandler.thrift.SW360Exception;
1819
import org.springframework.beans.factory.annotation.Autowired;
1920
import org.springframework.stereotype.Component;
2021

@@ -42,7 +43,7 @@ public class FossologyRestConfig {
4243
private boolean outdated;
4344

4445
@Autowired
45-
public FossologyRestConfig(ConfigContainerRepository repository) {
46+
public FossologyRestConfig(ConfigContainerRepository repository) throws SW360Exception {
4647
this.repository = repository;
4748
// eager loading (or initial insert)
4849
get();
@@ -67,7 +68,12 @@ public String getFolderId() {
6768
}
6869

6970
private String getFirstValue(String key) {
70-
return get().getConfigKeyToValues().getOrDefault(key, new HashSet<>()).stream().findFirst().orElse(null);
71+
try {
72+
return get().getConfigKeyToValues().getOrDefault(key, new HashSet<>()).stream().findFirst().orElse(null);
73+
} catch (SW360Exception e) {
74+
log.error(e);
75+
return null;
76+
}
7177
}
7278

7379
public ConfigContainer update(ConfigContainer newConfig) {
@@ -97,7 +103,13 @@ public ConfigContainer update(ConfigContainer newConfig) {
97103
throw new IllegalStateException("The new FOSSology REST configuration does not contain a valid folder id.");
98104
}
99105

100-
ConfigContainer current = get();
106+
ConfigContainer current;
107+
try {
108+
current = get();
109+
} catch (SW360Exception e) {
110+
log.error(e);
111+
throw new IllegalStateException("Unable to get container config.");
112+
}
101113
current.setConfigKeyToValues(newConfig.getConfigKeyToValues());
102114

103115
repository.update(current);
@@ -108,7 +120,7 @@ public ConfigContainer update(ConfigContainer newConfig) {
108120
return current;
109121
}
110122

111-
public ConfigContainer get() {
123+
public ConfigContainer get() throws SW360Exception {
112124
if (config == null || outdated) {
113125
try {
114126
config = repository.getByConfigFor(ConfigFor.FOSSOLOGY_REST);

backend/licenses-core/src/main/java/org/eclipse/sw360/licenses/db/LicenseDatabaseHandler.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -981,7 +981,12 @@ public RequestStatus addOrUpdateCustomProperties(CustomProperties customProperti
981981
if(customProperties.isSetId()){
982982
customPropertiesRepository.update(customProperties);
983983
} else {
984-
customPropertiesRepository.add(customProperties);
984+
try {
985+
customPropertiesRepository.add(customProperties);
986+
} catch (SW360Exception e) {
987+
log.error("Unable to add or update custom license property.", e);
988+
return RequestStatus.FAILURE;
989+
}
985990
}
986991
return RequestStatus.SUCCESS;
987992
}

backend/licenses/src/test/java/org/eclipse/sw360/licenses/LicenseHandlerTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import org.junit.Before;
2222
import org.junit.Test;
2323

24-
import java.net.MalformedURLException;
2524
import java.util.*;
2625

2726
import static org.junit.Assert.*;
@@ -167,7 +166,7 @@ public void testUpdateLicenseIdNotMatch() throws Exception {
167166
handler.updateLicense(invalidLicense, user, user);
168167
}
169168

170-
public void createTestEntries() throws MalformedURLException {
169+
public void createTestEntries() throws SW360Exception {
171170
// List of test objects
172171
licenses = new HashMap<>();
173172
obligs = new HashMap<>();

backend/moderation/src/main/java/org/eclipse/sw360/moderation/db/ModerationDatabaseHandler.java

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ public List<ModerationRequest> getRequestByDocumentId(String documentId) {
181181
return requests;
182182
}
183183

184-
public String createClearingRequest(ClearingRequest request, User user) {
184+
public String createClearingRequest(ClearingRequest request, User user) throws SW360Exception {
185185
request.setTimestamp(System.currentTimeMillis());
186186
long id = 1;
187187
synchronized (ModerationDatabaseHandler.class) {
@@ -441,7 +441,12 @@ public RequestStatus createRequest(Component component, User user, Boolean isDel
441441
if(component.isSetComponentType()) {
442442
request.setComponentType(component.getComponentType());
443443
}
444-
addOrUpdate(request, user);
444+
try {
445+
addOrUpdate(request, user);
446+
} catch (SW360Exception e) {
447+
log.error("Unable to update request.", e);
448+
return RequestStatus.FAILURE;
449+
}
445450
return RequestStatus.SENT_TO_MODERATOR;
446451
}
447452

@@ -476,7 +481,12 @@ public RequestStatus createRequest(Release release, User user, Boolean isDeleteR
476481
} catch (SW360Exception e) {
477482
log.error("Could not retrieve parent component type of release with ID=" + release.getId());
478483
}
479-
addOrUpdate(request, user);
484+
try {
485+
addOrUpdate(request, user);
486+
} catch (SW360Exception e) {
487+
log.error("Unable to update request.", e);
488+
return RequestStatus.FAILURE;
489+
}
480490
return RequestStatus.SENT_TO_MODERATOR;
481491
}
482492

@@ -551,7 +561,12 @@ public RequestStatus createRequest(Project project, User user, Boolean isDeleteR
551561
// Fill the request
552562
ModerationRequestGenerator generator = new ProjectModerationRequestGenerator();
553563
request = generator.setAdditionsAndDeletions(request, project, dbproject);
554-
addOrUpdate(request, user);
564+
try {
565+
addOrUpdate(request, user);
566+
} catch (SW360Exception e) {
567+
log.error("Unable to create request.", e);
568+
return RequestStatus.FAILURE;
569+
}
555570
return RequestStatus.SENT_TO_MODERATOR;
556571
}
557572

@@ -617,7 +632,12 @@ public RequestStatus createRequest(License license, User user) {
617632
// Fill the request
618633
ModerationRequestGenerator generator = new LicenseModerationRequestGenerator();
619634
request = generator.setAdditionsAndDeletions(request, license, dblicense);
620-
addOrUpdate(request, user);
635+
try {
636+
addOrUpdate(request, user);
637+
} catch (SW360Exception e) {
638+
log.error("Unable to create request.", e);
639+
return RequestStatus.FAILURE;
640+
}
621641
return RequestStatus.SENT_TO_MODERATOR;
622642
}
623643

@@ -633,7 +653,11 @@ public void createRequest(User user) {
633653
// Set the object
634654
request.setUser(user);
635655

636-
addOrUpdate(request, user);
656+
try {
657+
addOrUpdate(request, user);
658+
} catch (SW360Exception e) {
659+
log.error("Unable to create request.", e);
660+
}
637661
}
638662

639663
private Set<String> getSPDXDocumentModerators(String department, SPDXDocument dbSpdx) {
@@ -685,7 +709,12 @@ public RequestStatus createRequest(SPDXDocument spdx, User user, Boolean isDelet
685709
// Fill the request
686710
ModerationRequestGenerator generator = new SpdxDocumentModerationRequestGenerator();
687711
request = generator.setAdditionsAndDeletions(request, spdx, dbSpdx);
688-
addOrUpdate(request, user);
712+
try {
713+
addOrUpdate(request, user);
714+
} catch (SW360Exception e) {
715+
log.error("Unable to create request.", e);
716+
return RequestStatus.FAILURE;
717+
}
689718
return RequestStatus.SENT_TO_MODERATOR;
690719
}
691720

@@ -706,7 +735,12 @@ public RequestStatus createRequest(DocumentCreationInformation documentCreationI
706735
// Fill the request
707736
ModerationRequestGenerator generator = new SpdxDocumentCreationInfoModerationRequestGenerator();
708737
request = generator.setAdditionsAndDeletions(request, documentCreationInfo, dbDocumentCreationInfo);
709-
addOrUpdate(request, user);
738+
try {
739+
addOrUpdate(request, user);
740+
} catch (SW360Exception e) {
741+
log.error("Unable to create request.", e);
742+
return RequestStatus.FAILURE;
743+
}
710744
return RequestStatus.SENT_TO_MODERATOR;
711745
}
712746

@@ -727,7 +761,12 @@ public RequestStatus createRequest(PackageInformation packageInfo, User user, Bo
727761
// Fill the request
728762
ModerationRequestGenerator generator = new SpdxPackageInfoModerationRequestGenerator();
729763
request = generator.setAdditionsAndDeletions(request, packageInfo, dbPackageInfo);
730-
addOrUpdate(request, user);
764+
try {
765+
addOrUpdate(request, user);
766+
} catch (SW360Exception e) {
767+
log.error("Unable to create request.", e);
768+
return RequestStatus.FAILURE;
769+
}
731770
return RequestStatus.SENT_TO_MODERATOR;
732771
}
733772

@@ -846,10 +885,10 @@ private List<User> getAllSW360Users() {
846885
return sw360users;
847886
}
848887

849-
public void addOrUpdate(ModerationRequest request, User user) {
888+
public void addOrUpdate(ModerationRequest request, User user) throws SW360Exception {
850889
addOrUpdate(request, user.getEmail());
851890
}
852-
public void addOrUpdate(ModerationRequest request, String userEmail) {
891+
public void addOrUpdate(ModerationRequest request, String userEmail) throws SW360Exception {
853892
if (request.isSetId()) {
854893
repository.update(request);
855894
sendMailNotificationsForUpdatedRequest(request, userEmail);

backend/moderation/src/test/java/org/eclipse/sw360/moderation/testutil/DatabaseTestSetup.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import org.eclipse.sw360.datahandler.cloudantclient.DatabaseConnectorCloudant;
1414
import org.eclipse.sw360.datahandler.common.DatabaseSettingsTest;
15+
import org.eclipse.sw360.datahandler.thrift.SW360Exception;
1516
import org.eclipse.sw360.datahandler.thrift.moderation.DocumentType;
1617
import org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest;
1718
import org.eclipse.sw360.datahandler.thrift.projects.Project;
@@ -24,7 +25,7 @@
2425
public class DatabaseTestSetup {
2526

2627

27-
public static void main(String[] args) throws MalformedURLException {
28+
public static void main(String[] args) throws MalformedURLException, SW360Exception {
2829

2930
DatabaseConnectorCloudant db = new DatabaseConnectorCloudant(DatabaseSettingsTest.getConfiguredClient(), DatabaseSettingsTest.COUCH_DB_DATABASE);
3031

backend/utils/src/test/java/org/eclipse/sw360/attachments/db/RemoteAttachmentDownloaderTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ public void testWithBrokenURL() throws Exception {
167167
}
168168
}
169169

170-
private AttachmentContent saveRemoteAttachment(String remoteUrl) {
170+
private AttachmentContent saveRemoteAttachment(String remoteUrl) throws SW360Exception {
171171
AttachmentContent attachmentContent = new AttachmentContent()
172172
.setFilename("testfile")
173173
.setContentType("text")

0 commit comments

Comments
 (0)