Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API: new function returning pipelines visible for organization #525

Merged
merged 2 commits into from
Sep 9, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ public interface PipelineFacade extends Facade {
* @return List of pipelines
*/
List<Pipeline> getAllPipelines(String externalUserId);

/**
* Returns list of pipeline given user owns or that are not private
*
* @param externalUserId
* @return
*/
List<Pipeline> getAllVisiblePipelines(String externalUserId);

/**
* Find pipeline in database by ID and return it.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -657,4 +657,9 @@ public List<Pipeline> getAllPipelines(String externalUserId) {
return this.pipelineDao.getPipelinesForUser(externalUserId);
}

@PostFilter("hasPermission(filterObject,'pipeline.read')")
@Override
public List<Pipeline> getAllVisiblePipelines(String externalUserId) {
return this.pipelineDao.getAllVisiblePipelines(externalUserId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,16 @@ public interface DbPipeline extends DbAccess<Pipeline> {
*/
public List<Pipeline> getPipelinesForUser(String externalUserId);


/**
* Fetches all pipelines that are visible to user, so:
* <br/>
* - he is owner that pipeline
* - pipelines that are not private (owner is someone else)
*
* @param userExternalId
* @return
*/
public List<Pipeline> getAllVisiblePipelines(String userExternalId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import cz.cuni.mff.xrg.odcs.commons.app.auth.ShareType;
import cz.cuni.mff.xrg.odcs.commons.app.dao.db.DbAccessBase;
import cz.cuni.mff.xrg.odcs.commons.app.dpu.DPUTemplateRecord;

Expand Down Expand Up @@ -105,4 +106,15 @@ public List<Pipeline> getPipelinesForUser(String userExternalId) {
query.setParameter("userExternalId", userExternalId);
return executeList(query);
}

@Override
public List<Pipeline> getAllVisiblePipelines(String userExternalId) {
final String queryStr = "SELECT e FROM Pipeline e"
+ " WHERE e.owner.externalIdentifier = :userExternalId"
+ " OR e.shareType != :shareType";
TypedQuery<Pipeline> query = createTypedQuery(queryStr);
query.setParameter("userExternalId", userExternalId);
query.setParameter("shareType", ShareType.PRIVATE);
return executeList(query);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
package eu.unifiedviews.master.api;

import static org.apache.commons.lang3.StringUtils.isEmpty;
import static org.apache.commons.lang3.StringUtils.isNotEmpty;

import java.io.File;
Expand Down Expand Up @@ -45,7 +44,6 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import cz.cuni.mff.xrg.odcs.commons.app.conf.AppConfig;
import cz.cuni.mff.xrg.odcs.commons.app.facade.PipelineFacade;
import cz.cuni.mff.xrg.odcs.commons.app.facade.UserFacade;
import cz.cuni.mff.xrg.odcs.commons.app.pipeline.Pipeline;
Expand Down Expand Up @@ -122,7 +120,7 @@ public List<PipelineDTO> getPipelines(@QueryParam("userExternalId") String userE
if (isNotEmpty(userExternalId)) {
pipelines = this.pipelineFacade.getAllPipelines(userExternalId);
} else {
pipelines = this.pipelineFacade.getAllPipelines();
pipelines = new ArrayList<>();
}

if (pipelines == null) {
Expand All @@ -136,6 +134,25 @@ public List<PipelineDTO> getPipelines(@QueryParam("userExternalId") String userE

return PipelineDTOConverter.convert(pipelines);
}

@GET
@Path("/visible")
@Produces({ MediaType.APPLICATION_JSON })
public List<PipelineDTO> getVisiblePipelines(@QueryParam("userExternalId") String userExternalId) {
List<Pipeline> pipelines = null;
try{
pipelines = this.pipelineFacade.getAllVisiblePipelines(userExternalId);

if (pipelines == null) {
pipelines = new ArrayList<>();
}
} catch (ApiException e) {
throw e;
} catch (RuntimeException e) {
throw new ApiException(Response.Status.INTERNAL_SERVER_ERROR, Messages.getString("pipeline.get.general.error"), e.getMessage());
}
return PipelineDTOConverter.convert(pipelines);
}

@GET
@Path("/{pipelineid}")
Expand Down