-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rest): Update REST Attachment endpoints and documentation
- update documentation - refactored attachment service - added attachment endpoints Signed-off-by: Thomas Maier <thomas.maier@evosoft.com>
- Loading branch information
1 parent
93cee8b
commit 8d36000
Showing
38 changed files
with
776 additions
and
395 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
...rc-common/src/main/java/org/eclipse/sw360/datahandler/db/AttachmentContentRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Copyright Siemens AG, 2013-2015. Part of the SW360 Portal Project. | ||
* | ||
* SPDX-License-Identifier: EPL-1.0 | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
*/ | ||
|
||
package org.eclipse.sw360.datahandler.db; | ||
|
||
import org.eclipse.sw360.datahandler.couchdb.DatabaseConnector; | ||
import org.eclipse.sw360.datahandler.couchdb.DatabaseRepository; | ||
import org.eclipse.sw360.datahandler.permissions.PermissionUtils; | ||
import org.eclipse.sw360.datahandler.thrift.RequestStatus; | ||
import org.eclipse.sw360.datahandler.thrift.RequestSummary; | ||
import org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent; | ||
import org.eclipse.sw360.datahandler.thrift.users.User; | ||
import org.ektorp.DocumentOperationResult; | ||
import org.ektorp.ViewQuery; | ||
import org.ektorp.support.View; | ||
import org.ektorp.support.Views; | ||
|
||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* CRUD access for the Attachment class | ||
* | ||
* @author cedric.bodet@tngtech.com | ||
* @author Johannes.Najjar@tngtech.com | ||
* @author daniele.fognini@tngtech.com | ||
*/ | ||
@Views({ | ||
@View(name = "all", map = "function(doc) { if (doc.type == 'attachment') emit(null, doc._id) }"), | ||
@View(name = "onlyRemotes", map = "function(doc) { if(doc.type == 'attachment' && doc.onlyRemote) { emit(null, doc) } }") | ||
}) | ||
public class AttachmentContentRepository extends DatabaseRepository<AttachmentContent> { | ||
|
||
public AttachmentContentRepository(DatabaseConnector db) { | ||
super(AttachmentContent.class, db); | ||
|
||
initStandardDesignDocument(); | ||
} | ||
|
||
public List<AttachmentContent> getOnlyRemoteAttachments() { | ||
ViewQuery query = createQuery("onlyRemotes"); | ||
query.includeDocs(false); | ||
return queryView(query); | ||
} | ||
|
||
public RequestSummary vacuumAttachmentDB(User user, final Set<String> usedIds) { | ||
final RequestSummary requestSummary = new RequestSummary(); | ||
if (!PermissionUtils.isAdmin(user)) | ||
return requestSummary.setRequestStatus(RequestStatus.FAILURE); | ||
|
||
final List<AttachmentContent> allAttachmentContents = getAll(); | ||
final Set<AttachmentContent> unusedAttachmentContents = allAttachmentContents.stream() | ||
.filter(input -> !usedIds.contains(input.getId())) | ||
.collect(Collectors.toSet()); | ||
|
||
requestSummary.setTotalElements(allAttachmentContents.size()); | ||
requestSummary.setTotalAffectedElements(unusedAttachmentContents.size()); | ||
|
||
final List<DocumentOperationResult> documentOperationResults = deleteBulk(unusedAttachmentContents); | ||
if (documentOperationResults.isEmpty()) { | ||
requestSummary.setRequestStatus(RequestStatus.SUCCESS); | ||
}else{ | ||
requestSummary.setRequestStatus(RequestStatus.FAILURE); | ||
} | ||
return requestSummary; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
.../src-common/src/main/java/org/eclipse/sw360/datahandler/db/AttachmentOwnerRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright Siemens AG, 2018. Part of the SW360 Portal Project. | ||
* | ||
* SPDX-License-Identifier: EPL-1.0 | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
*/ | ||
package org.eclipse.sw360.datahandler.db; | ||
|
||
import org.eclipse.sw360.datahandler.couchdb.DatabaseConnector; | ||
import org.eclipse.sw360.datahandler.couchdb.DatabaseRepository; | ||
import org.eclipse.sw360.datahandler.thrift.Source; | ||
import org.ektorp.ViewQuery; | ||
import org.ektorp.support.View; | ||
import org.ektorp.support.Views; | ||
|
||
import java.util.List; | ||
import java.util.Set; | ||
|
||
@Views({ | ||
@View(name = "attachmentOwner", | ||
map = "function(doc) { if (doc.type == 'project' || doc.type == 'component' || doc.type == 'release') { " + | ||
"for(var i in doc.attachments) { " + | ||
"var source;" + | ||
"if (doc.type == 'project') {source = {projectId: doc._id}}" + | ||
"if (doc.type == 'component') {source = {componentId: doc._id}}" + | ||
"if (doc.type == 'release') {source = {releaseId: doc._id}}" + | ||
"emit(doc.attachments[i].attachmentContentId, source); } } }") | ||
}) | ||
|
||
public class AttachmentOwnerRepository extends DatabaseRepository<Source> { | ||
|
||
public AttachmentOwnerRepository(DatabaseConnector db) { | ||
super(Source.class, db); | ||
initStandardDesignDocument(); | ||
} | ||
|
||
public List<Source> getOwnersByIds(Set<String> ids) { | ||
ViewQuery viewQuery = createQuery("attachmentOwner").includeDocs(false).keys(ids); | ||
return queryView(viewQuery); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.