use of com.helger.commons.state.EChange in project phoss-smp by phax.
the class SMLInfoManagerXML method updateSMLInfo.
@Nonnull
public EChange updateSMLInfo(@Nullable final String sSMLInfoID, @Nonnull @Nonempty final String sDisplayName, @Nonnull @Nonempty final String sDNSZone, @Nonnull @Nonempty final String sManagementServiceURL, final boolean bClientCertificateRequired) {
final SMLInfo aSMLInfo = getOfID(sSMLInfoID);
if (aSMLInfo == null) {
AuditHelper.onAuditModifyFailure(SMLInfo.OT, "set-all", sSMLInfoID, "no-such-id");
return EChange.UNCHANGED;
}
m_aRWLock.writeLock().lock();
try {
EChange eChange = EChange.UNCHANGED;
eChange = eChange.or(aSMLInfo.setDisplayName(sDisplayName));
eChange = eChange.or(aSMLInfo.setDNSZone(sDNSZone));
eChange = eChange.or(aSMLInfo.setManagementServiceURL(sManagementServiceURL));
eChange = eChange.or(aSMLInfo.setClientCertificateRequired(bClientCertificateRequired));
if (eChange.isUnchanged())
return EChange.UNCHANGED;
internalUpdateItem(aSMLInfo);
} finally {
m_aRWLock.writeLock().unlock();
}
AuditHelper.onAuditModifySuccess(SMLInfo.OT, "set-all", sSMLInfoID, sDisplayName, sDNSZone, sManagementServiceURL, Boolean.valueOf(bClientCertificateRequired));
return EChange.CHANGED;
}
use of com.helger.commons.state.EChange in project phoss-smp by phax.
the class SMPTransportProfileManagerXML method updateSMPTransportProfile.
@Nonnull
public EChange updateSMPTransportProfile(@Nullable final String sSMPTransportProfileID, @Nonnull @Nonempty final String sName, final boolean bIsDeprecated) {
final SMPTransportProfile aSMPTransportProfile = getOfID(sSMPTransportProfileID);
if (aSMPTransportProfile == null) {
AuditHelper.onAuditModifyFailure(SMPTransportProfile.OT, "set-all", sSMPTransportProfileID, "no-such-id");
return EChange.UNCHANGED;
}
m_aRWLock.writeLock().lock();
try {
EChange eChange = EChange.UNCHANGED;
eChange = eChange.or(aSMPTransportProfile.setName(sName));
eChange = eChange.or(aSMPTransportProfile.setDeprecated(bIsDeprecated));
if (eChange.isUnchanged())
return EChange.UNCHANGED;
internalUpdateItem(aSMPTransportProfile);
} finally {
m_aRWLock.writeLock().unlock();
}
AuditHelper.onAuditModifySuccess(SMPTransportProfile.OT, "set-all", sSMPTransportProfileID, sName, Boolean.valueOf(bIsDeprecated));
return EChange.CHANGED;
}
use of com.helger.commons.state.EChange 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.state.EChange in project peppol-practical by phax.
the class CommentThreadManager method updateCommentState.
@Nonnull
public EChange updateCommentState(@Nonnull final ITypedObject<String> aOwner, @Nullable final String sCommentThreadID, @Nullable final String sCommentID, @Nonnull final ECommentState eNewState) {
// Get/create the object type comment manager
final CommentThreadObjectTypeManager aMgr = getManagerOfObjectType(aOwner.getObjectType());
if (aMgr == null)
return EChange.UNCHANGED;
// Remove from respective manager
final EChange eChange = aMgr.updateCommentState(aOwner.getID(), sCommentThreadID, sCommentID, eNewState);
if (eChange.isChanged())
STATS_COUNTER_COMMENT_REMOVE.increment();
return eChange;
}
use of com.helger.commons.state.EChange in project ph-commons by phax.
the class ICommonsCollection method addAllMapped.
/**
* Add all passed elements matching the provided filter after performing a
* mapping using the provided function.
*
* @param aElements
* The elements to be added after mapping. May be <code>null</code>.
* @param aFilter
* The filter to be applied. May be <code>null</code>.
* @param aMapper
* The mapping function to be executed for all provided elements. May
* not be <code>null</code>.
* @return {@link EChange#CHANGED} if at least one element was added,
* {@link EChange#UNCHANGED}. Never <code>null</code>.
* @param <SRCTYPE>
* The source type to be mapped from
*/
@Nonnull
default <SRCTYPE> EChange addAllMapped(@Nullable final Iterable<? extends SRCTYPE> aElements, @Nullable final Predicate<? super SRCTYPE> aFilter, @Nonnull final Function<? super SRCTYPE, ? extends ELEMENTTYPE> aMapper) {
ValueEnforcer.notNull(aMapper, "Mapper");
if (aFilter == null)
return addAllMapped(aElements, aMapper);
EChange eChange = EChange.UNCHANGED;
if (aElements != null)
for (final SRCTYPE aValue : aElements) if (aFilter.test(aValue))
eChange = eChange.or(add(aMapper.apply(aValue)));
return eChange;
}
Aggregations