use of com.helger.commons.type.ObjectType in project peppol-practical by phax.
the class AjaxExecutorCommentAdd method handleRequest.
public void handleRequest(@Nonnull final IRequestWebScopeWithoutResponse aRequestScope, @Nonnull final PhotonUnifiedResponse aAjaxResponse) throws Exception {
final LayoutExecutionContext aLEC = LayoutExecutionContext.createForAjaxOrAction(aRequestScope);
final Locale aDisplayLocale = aLEC.getDisplayLocale();
final String sObjectType = aRequestScope.params().getAsString(PARAM_OBJECT_TYPE);
final String sObjectID = aRequestScope.params().getAsString(PARAM_OBJECT_ID);
final String sCommentThreadID = aRequestScope.params().getAsString(PARAM_COMMENT_THREAD_ID);
final String sCommentID = aRequestScope.params().getAsString(PARAM_COMMENT_ID);
String sAuthor = aRequestScope.params().getAsString(PARAM_AUTHOR);
final String sTitle = aRequestScope.params().getAsString(PARAM_TITLE);
final String sText = aRequestScope.params().getAsString(PARAM_TEXT);
// Get info on current user
final IUser aCurrentUser = LoggedInUserManager.getInstance().getCurrentUser();
final String sCurrentUserID = aCurrentUser != null ? aCurrentUser.getID() : null;
if (aCurrentUser != null)
sAuthor = aCurrentUser.getDisplayName();
if (StringHelper.hasText(sObjectType) && StringHelper.hasText(sObjectID) && StringHelper.hasText(sCommentThreadID) && StringHelper.hasText(sCommentID) && CommentSecurity.canCurrentUserPostComments()) {
// Create a dummy object
final ITypedObject<String> aOwner = TypedObject.create(new ObjectType(sObjectType), sObjectID);
final ICommentThread aCommentThread = CommentThreadManager.getInstance().getCommentThreadOfID(aOwner, sCommentThreadID);
if (aCommentThread != null) {
final IComment aParentComment = aCommentThread.getCommentOfID(sCommentID);
if (aParentComment != null) {
final CommentFormErrors aFormErrors = CommentFormErrors.createForReply(aCommentThread, aParentComment);
if (StringHelper.hasNoText(sAuthor)) {
// No author provided
aFormErrors.addFieldError(PARAM_AUTHOR, ECommentText.MSG_ERR_COMMENT_NO_AUTHOR.getDisplayText(aDisplayLocale));
}
if (StringHelper.hasNoText(sText)) {
// No text provided
aFormErrors.addFieldError(PARAM_TEXT, ECommentText.MSG_ERR_COMMENT_NO_TEXT.getDisplayText(aDisplayLocale));
}
IHCNode aMessageBox = null;
if (aFormErrors.isEmpty()) {
// Go ahead and save
final ESuccess eSuccess = CommentThreadManager.getInstance().addCommentToThread(aOwner, sCommentThreadID, sCommentID, new Comment(aRequestScope.getRemoteHost(), ECommentState.APPROVED, sCurrentUserID, sAuthor, sTitle, sText));
if (eSuccess.isSuccess())
aMessageBox = success(ECommentText.MSG_COMMENT_SAVE_SUCCESS.getDisplayText(aDisplayLocale));
else
aMessageBox = error(ECommentText.MSG_COMMENT_SAVE_FAILURE.getDisplayText(aDisplayLocale));
}
// List of exiting comments + message box
aAjaxResponse.html(CommentUI.getCommentList(aLEC, aOwner, CommentAction.createForComment(ECommentAction.ADD_COMMENT, aCommentThread, aParentComment), aFormErrors, aMessageBox, true));
return;
}
}
}
// Somebody played around with the API
LOGGER.warn("Failed to resolve comment object type '" + sObjectType + "' and/or object ID '" + sObjectID + "' for adding to comment '" + sCommentID + "' in thread '" + sCommentThreadID + "'");
aAjaxResponse.createNotFound();
}
use of com.helger.commons.type.ObjectType in project peppol-practical by phax.
the class AjaxExecutorCommentCreateThread method handleRequest.
public void handleRequest(@Nonnull final IRequestWebScopeWithoutResponse aRequestScope, @Nonnull final PhotonUnifiedResponse aAjaxResponse) throws Exception {
final LayoutExecutionContext aLEC = LayoutExecutionContext.createForAjaxOrAction(aRequestScope);
final Locale aDisplayLocale = aLEC.getDisplayLocale();
final String sObjectType = aRequestScope.params().getAsString(PARAM_OBJECT_TYPE);
final String sObjectID = aRequestScope.params().getAsString(PARAM_OBJECT_ID);
String sAuthor = aRequestScope.params().getAsString(PARAM_AUTHOR);
final String sTitle = aRequestScope.params().getAsString(PARAM_TITLE);
final String sText = aRequestScope.params().getAsString(PARAM_TEXT);
// Get info on current user
final IUser aCurrentUser = LoggedInUserManager.getInstance().getCurrentUser();
final String sCurrentUserID = aCurrentUser != null ? aCurrentUser.getID() : null;
if (aCurrentUser != null)
sAuthor = aCurrentUser.getDisplayName();
if (StringHelper.hasText(sObjectType) && StringHelper.hasText(sObjectID) && CommentSecurity.canCurrentUserPostComments()) {
// Create a dummy object
final ITypedObject<String> aOwner = TypedObject.create(new ObjectType(sObjectType), sObjectID);
final CommentFormErrors aFormErrors = CommentFormErrors.createForNewThread();
if (StringHelper.hasNoText(sAuthor)) {
// No author provided
aFormErrors.addFieldError(PARAM_AUTHOR, ECommentText.MSG_ERR_COMMENT_NO_AUTHOR.getDisplayText(aDisplayLocale));
}
if (StringHelper.hasNoText(sText)) {
// No text provided
aFormErrors.addFieldError(PARAM_TEXT, ECommentText.MSG_ERR_COMMENT_NO_TEXT.getDisplayText(aDisplayLocale));
}
IHCNode aMessageBox = null;
if (aFormErrors.isEmpty()) {
// Go ahead and save
final ICommentThread aNewThread = CommentThreadManager.getInstance().createNewThread(aOwner, new Comment(aRequestScope.getRemoteHost(), ECommentState.APPROVED, sCurrentUserID, sAuthor, sTitle, sText));
if (aNewThread != null)
aMessageBox = success(ECommentText.MSG_COMMENT_SAVE_SUCCESS.getDisplayText(aDisplayLocale));
else
aMessageBox = error(ECommentText.MSG_COMMENT_SAVE_FAILURE.getDisplayText(aDisplayLocale));
}
// List of exiting comments + message box
aAjaxResponse.html(CommentUI.getCommentList(aLEC, aOwner, CommentAction.createGeneric(ECommentAction.CREATE_THREAD), aFormErrors, aMessageBox, true));
return;
}
// Somebody played around with the API
LOGGER.warn("Failed to resolve comment object type '" + sObjectType + "' and/or object ID '" + sObjectID + "'");
aAjaxResponse.createNotFound();
}
use of com.helger.commons.type.ObjectType in project peppol-practical by phax.
the class PageSecureCommentAdmin method fillContent.
@Override
protected void fillContent(@Nonnull final WebPageExecutionContext aWPEC) {
final Locale aDisplayLocale = aWPEC.getDisplayLocale();
final HCNodeList aNodeList = aWPEC.getNodeList();
final CommentThreadManager aCommentThreadMgr = CommentThreadManager.getInstance();
boolean bShowList = true;
final String sSelectedObjectType = aWPEC.params().getAsString(PARAM_TYPE);
final String sSelectedOwningObjectID = aWPEC.params().getAsString(CPageParam.PARAM_OBJECT);
if (aWPEC.hasAction(CPageParam.ACTION_VIEW) && StringHelper.hasText(sSelectedObjectType) && StringHelper.hasText(sSelectedOwningObjectID)) {
final TypedObject<String> aTO = TypedObject.create(new ObjectType(sSelectedObjectType), sSelectedOwningObjectID);
final List<ICommentThread> aCommentThreads = aCommentThreadMgr.getAllCommentThreadsOfObject(aTO);
if (!aCommentThreads.isEmpty()) {
// Don't allow comment creation
aNodeList.addChild(CommentUI.getCommentList(aWPEC, aTO, CommentAction.createGeneric(ECommentAction.NONE), null, null, false));
// Toolbar
final IButtonToolbar<?> aToolbar = new BootstrapButtonToolbar(aWPEC);
aToolbar.addButton(EPhotonCoreText.BACK_TO_OVERVIEW.getDisplayText(aDisplayLocale), aWPEC.getSelfHref(), EDefaultIcon.BACK_TO_LIST);
aNodeList.addChild(aToolbar);
bShowList = false;
}
}
if (bShowList) {
// Refresh button
final IButtonToolbar<?> aToolbar = new BootstrapButtonToolbar(aWPEC);
aToolbar.addButton(EPhotonCoreText.BUTTON_REFRESH.getDisplayText(aDisplayLocale), aWPEC.getSelfHref(), EDefaultIcon.REFRESH);
aNodeList.addChild(aToolbar);
final ITabBox<?> aTabBox = new BootstrapTabBox();
for (final ObjectType aOT : CollectionHelper.getSorted(aCommentThreadMgr.getAllRegisteredObjectTypes())) {
final HCNodeList aTab = new HCNodeList();
final HCTable aTable = new HCTable(new DTCol(EText.HEADER_OBJECT_ID.getDisplayText(aDisplayLocale)), new DTCol(EText.HEADER_THREADS.getDisplayText(aDisplayLocale)).addClass(CSS_CLASS_RIGHT).setDisplayType(EDTColType.INT, aDisplayLocale), new DTCol(EText.HEADER_COMMENTS.getDisplayText(aDisplayLocale)).addClass(CSS_CLASS_RIGHT).setDisplayType(EDTColType.INT, aDisplayLocale), new DTCol(EText.HEADER_ACTIVE_COMMENTS.getDisplayText(aDisplayLocale)).addClass(CSS_CLASS_RIGHT).setDisplayType(EDTColType.INT, aDisplayLocale), new DTCol(EText.HEADER_LAST_CHANGE.getDisplayText(aDisplayLocale)).addClass(CSS_CLASS_RIGHT).setDisplayType(EDTColType.DATETIME, aDisplayLocale).setInitialSorting(ESortOrder.DESCENDING)).setID(getID() + aOT.getName());
final CommentThreadObjectTypeManager aCTOTMgr = aCommentThreadMgr.getManagerOfObjectType(aOT);
for (final Map.Entry<String, ICommonsList<ICommentThread>> aEntry : aCTOTMgr.getAllCommentThreads().entrySet()) {
final String sOwningObjectID = aEntry.getKey();
final ISimpleURL aViewURL = AbstractWebPageForm.createViewURL(aWPEC, sOwningObjectID).add(PARAM_TYPE, aOT.getName());
final HCRow aRow = aTable.addBodyRow();
aRow.addCell(new HCA(aViewURL).addChild(sOwningObjectID));
aRow.addCell(Integer.toString(aEntry.getValue().size()));
int nActiveComments = 0;
final ICommonsList<IComment> aAllComments = new CommonsArrayList<>();
for (final ICommentThread aCommentThread : aEntry.getValue()) {
aAllComments.addAll(aCommentThread.getAllComments());
nActiveComments += aCommentThread.getTotalActiveCommentCount();
}
Collections.sort(aAllComments, Comparator.comparing(IComment::getLastChangeDateTime).reversed());
aRow.addCell(Integer.toString(aAllComments.size()));
aRow.addCell(Integer.toString(nActiveComments));
if (aAllComments.isEmpty())
aRow.addCell();
else
aRow.addCell(PDTToString.getAsString(aAllComments.get(0).getLastChangeDateTime(), aDisplayLocale));
}
aTab.addChild(aTable);
final DataTables aDataTables = BootstrapDataTables.createDefaultDataTables(aWPEC, aTable);
aTab.addChild(aDataTables);
aTabBox.addTab(aOT.getName(), aOT.getName(), aTab, aOT.getName().equals(sSelectedObjectType));
}
aNodeList.addChild(aTabBox);
}
}
use of com.helger.commons.type.ObjectType in project peppol-practical by phax.
the class AjaxExecutorCommentDelete method handleRequest.
public void handleRequest(@Nonnull final IRequestWebScopeWithoutResponse aRequestScope, @Nonnull final PhotonUnifiedResponse aAjaxResponse) throws Exception {
final LayoutExecutionContext aLEC = LayoutExecutionContext.createForAjaxOrAction(aRequestScope);
final Locale aDisplayLocale = aLEC.getDisplayLocale();
final String sObjectType = aRequestScope.params().getAsString(PARAM_OBJECT_TYPE);
final String sObjectID = aRequestScope.params().getAsString(PARAM_OBJECT_ID);
final String sCommentThreadID = aRequestScope.params().getAsString(PARAM_COMMENT_THREAD_ID);
final String sCommentID = aRequestScope.params().getAsString(PARAM_COMMENT_ID);
if (StringHelper.hasText(sObjectType) && StringHelper.hasText(sObjectID) && StringHelper.hasText(sCommentThreadID) && StringHelper.hasText(sCommentID) && CommentSecurity.isCurrentUserCommentModerator()) {
// Create a dummy object
final ITypedObject<String> aOwner = TypedObject.create(new ObjectType(sObjectType), sObjectID);
final ICommentThread aCommentThread = CommentThreadManager.getInstance().getCommentThreadOfID(aOwner, sCommentThreadID);
if (aCommentThread != null) {
final IComment aParentComment = aCommentThread.getCommentOfID(sCommentID);
if (aParentComment != null) {
// Go ahead and delete
final EChange eChange = CommentThreadManager.getInstance().updateCommentState(aOwner, sCommentThreadID, sCommentID, ECommentState.DELETED_BY_MODERATOR);
IHCNode aMessageBox;
if (eChange.isChanged())
aMessageBox = success(ECommentText.MSG_COMMENT_DELETE_SUCCESS.getDisplayText(aDisplayLocale));
else
aMessageBox = error(ECommentText.MSG_COMMENT_DELETE_FAILURE.getDisplayText(aDisplayLocale));
// Message box + list of exiting comments
aAjaxResponse.html(CommentUI.getCommentList(aLEC, aOwner, CommentAction.createForComment(ECommentAction.DELETE_COMMENT, aCommentThread, aParentComment), null, aMessageBox, true));
return;
}
}
}
// Somebody played around with the API
LOGGER.warn("Failed to resolve comment object type '" + sObjectType + "' and/or object ID '" + sObjectID + "' for deletion of comment '" + sCommentID + "' in thread '" + sCommentThreadID + "'");
aAjaxResponse.createNotFound();
}
use of com.helger.commons.type.ObjectType in project peppol-practical by phax.
the class AjaxExecutorCommentShowInput method handleRequest.
public void handleRequest(@Nonnull final IRequestWebScopeWithoutResponse aRequestScope, @Nonnull final PhotonUnifiedResponse aAjaxResponse) throws Exception {
final LayoutExecutionContext aLEC = LayoutExecutionContext.createForAjaxOrAction(aRequestScope);
final String sObjectType = aRequestScope.params().getAsString(PARAM_OBJECT_TYPE);
final String sObjectID = aRequestScope.params().getAsString(PARAM_OBJECT_ID);
final String sCommentThreadID = aRequestScope.params().getAsString(PARAM_COMMENT_THREAD_ID);
final String sCommentID = aRequestScope.params().getAsString(PARAM_COMMENT_ID);
final String sResultDivID = aRequestScope.params().getAsString(PARAM_RESULT_DIV_ID);
if (StringHelper.hasText(sObjectType) && StringHelper.hasText(sObjectID) && StringHelper.hasText(sCommentThreadID) && StringHelper.hasText(sCommentID) && CommentSecurity.canCurrentUserPostComments()) {
// Create a dummy object
final ITypedObject<String> aOwner = TypedObject.create(new ObjectType(sObjectType), sObjectID);
final ICommentThread aCommentThread = CommentThreadManager.getInstance().getCommentThreadOfID(aOwner, sCommentThreadID);
if (aCommentThread != null) {
final IComment aParentComment = aCommentThread.getCommentOfID(sCommentID);
if (aParentComment != null) {
// response
final IHCNode aNode = CommentUI.getCreateComment(aLEC, sResultDivID, aOwner, aCommentThread, aParentComment, null, null);
aAjaxResponse.html(aNode);
return;
}
}
}
// Somebody played around with the API
LOGGER.warn("Failed to resolve comment object type '" + sObjectType + "' and/or object ID '" + sObjectID + "' for showing input of comment '" + sCommentID + "' in thread '" + sCommentThreadID + "'");
aAjaxResponse.createNotFound();
}
Aggregations