use of org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest in project sw360portal by sw360.
the class ModerationPortlet method renderActionView.
private void renderActionView(RenderRequest request, RenderResponse response) throws IOException, PortletException {
final User user = UserCacheHolder.getUserFromRequest(request);
final String id = request.getParameter(MODERATION_ID);
String sessionMessage;
if (id != null) {
try {
ModerationService.Iface client = thriftClients.makeModerationClient();
ModerationRequest moderationRequest = client.getModerationRequestById(id);
String action = request.getParameter(ACTION);
String encodedModerationComment = request.getParameter(MODERATION_DECISION_COMMENT);
String moderationComment = "";
if (encodedModerationComment != null) {
moderationComment = new String(Base64.getDecoder().decode(encodedModerationComment));
}
if (ACTION_CANCEL.equals(action)) {
client.cancelInProgress(id);
sessionMessage = "You have cancelled working on the previous moderation request.";
} else if (ACTION_DECLINE.equals(action)) {
declineModerationRequest(user, moderationRequest, request);
client.refuseRequest(id, moderationComment, user.getEmail());
sessionMessage = "You have declined the previous moderation request.";
} else if (ACTION_ACCEPT.equals(action)) {
String requestingUserEmail = moderationRequest.getRequestingUser();
User requestingUser = UserCacheHolder.getUserFromEmail(requestingUserEmail);
acceptModerationRequest(user, requestingUser, moderationRequest, request);
client.acceptRequest(moderationRequest, moderationComment, user.getEmail());
sessionMessage = "You have accepted the previous moderation request.";
} else if (ACTION_POSTPONE.equals(action)) {
// keep me assigned but do it later... so nothing to be done here, just update the comment message
moderationRequest.setCommentDecisionModerator(moderationComment);
client.updateModerationRequest(moderationRequest);
sessionMessage = "You have postponed the previous moderation request.";
} else if (ACTION_RENDER_NEXT_AFTER_UNSUBSCRIBE.equals(action)) {
sessionMessage = "You are removed from the list of moderators for the previous moderation request.";
} else {
throw new PortletException("Unknown action");
}
// ! Actions are processed now we go and render the next one
renderNextModeration(request, response, user, sessionMessage, client, moderationRequest);
} catch (TException e) {
log.error("Error in Moderation ", e);
}
}
}
use of org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest in project sw360portal by sw360.
the class MyTaskSubmissionsPortlet method doView.
@Override
public void doView(RenderRequest request, RenderResponse response) throws IOException, PortletException {
List<ModerationRequest> moderations = null;
try {
final User user = UserCacheHolder.getUserFromRequest(request);
moderations = thriftClients.makeModerationClient().getRequestsByRequestingUser(user);
} catch (TException e) {
log.error("Could not fetch your moderations from backend", e);
}
request.setAttribute(PortalConstants.MODERATION_REQUESTS, CommonUtils.nullToEmptyList(moderations));
super.doView(request, response);
}
use of org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest in project sw360portal by sw360.
the class ModerationPortlet method renderComponentModeration.
public void renderComponentModeration(RenderRequest request, RenderResponse response, ModerationRequest moderationRequest, User user) throws IOException, PortletException, TException {
final boolean requestDocumentDelete = moderationRequest.isRequestDocumentDelete();
Boolean is_used = false;
Component actual_component = null;
try {
ComponentService.Iface client = thriftClients.makeComponentClient();
actual_component = client.getComponentById(moderationRequest.getDocumentId(), user);
is_used = client.componentIsUsed(actual_component.getId());
} catch (TException e) {
log.error("Could not retrieve component", e);
}
if (actual_component == null) {
renderNextModeration(request, response, user, "Ignored unretrievable target", thriftClients.makeModerationClient(), moderationRequest);
return;
}
if (refuseToDeleteUsedDocument(request, response, moderationRequest, user, requestDocumentDelete, is_used))
return;
prepareComponent(request, user, actual_component);
request.setAttribute(PortalConstants.ACTUAL_COMPONENT, actual_component);
if (moderationRequest.isRequestDocumentDelete()) {
include("/html/moderation/components/delete.jsp", request, response);
} else {
include("/html/moderation/components/merge.jsp", request, response);
}
}
use of org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest in project sw360portal by sw360.
the class DatabaseTestSetup method main.
public static void main(String[] args) throws MalformedURLException {
DatabaseConnector db = new DatabaseConnector(DatabaseSettings.getConfiguredHttpClient(), DatabaseSettings.COUCH_DB_DATABASE);
Project project = new Project().setName("Test Project");
project.addToModerators("user1");
db.add(project);
ModerationRequest moderationRequest = new ModerationRequest();
moderationRequest.setDocumentId(project.id).setDocumentType(DocumentType.PROJECT);
moderationRequest.setRequestingUser("cedric.bodet@tngtech.com");
moderationRequest.addToModerators("cedric.bodet@tngtech.com");
db.add(moderationRequest);
}
use of org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest in project sw360portal by sw360.
the class TestModerationClient method main.
public static void main(String[] args) throws TException, IOException {
THttpClient thriftClient = new THttpClient("http://127.0.0.1:8080//moderation/thrift");
TProtocol protocol = new TCompactProtocol(thriftClient);
ModerationService.Iface client = new ModerationService.Client(protocol);
List<ModerationRequest> requestsByModerator = client.getRequestsByModerator(new User().setId("").setEmail("cedric.bodet@tngtech.com").setDepartment("BB"));
System.out.println("Fetched " + requestsByModerator.size() + " moderation requests from moderation service");
}
Aggregations