Search in sources :

Example 36 with EChange

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;
}
Also used : SMLInfo(com.helger.peppol.sml.SMLInfo) ISMLInfo(com.helger.peppol.sml.ISMLInfo) EChange(com.helger.commons.state.EChange) Nonnull(javax.annotation.Nonnull)

Example 37 with EChange

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;
}
Also used : EChange(com.helger.commons.state.EChange) ISMPTransportProfile(com.helger.peppol.smp.ISMPTransportProfile) SMPTransportProfile(com.helger.peppol.smp.SMPTransportProfile) ESMPTransportProfile(com.helger.peppol.smp.ESMPTransportProfile) Nonnull(javax.annotation.Nonnull)

Example 38 with EChange

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();
}
Also used : Locale(java.util.Locale) LayoutExecutionContext(com.helger.photon.core.execcontext.LayoutExecutionContext) ObjectType(com.helger.commons.type.ObjectType) IComment(com.helger.peppol.comment.domain.IComment) EChange(com.helger.commons.state.EChange) ICommentThread(com.helger.peppol.comment.domain.ICommentThread) IHCNode(com.helger.html.hc.IHCNode)

Example 39 with EChange

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;
}
Also used : EChange(com.helger.commons.state.EChange) Nonnull(javax.annotation.Nonnull)

Example 40 with 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;
}
Also used : EChange(com.helger.commons.state.EChange) Nonnull(javax.annotation.Nonnull)

Aggregations

EChange (com.helger.commons.state.EChange)50 Nonnull (javax.annotation.Nonnull)42 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)9 ISMPServiceGroup (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup)9 ISMPServiceGroupManager (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager)9 SMPServerException (com.helger.phoss.smp.exception.SMPServerException)7 CommonsHashMap (com.helger.commons.collection.impl.CommonsHashMap)6 ICommonsMap (com.helger.commons.collection.impl.ICommonsMap)6 IIdentifierFactory (com.helger.peppolid.factory.IIdentifierFactory)6 SMPNotFoundException (com.helger.phoss.smp.exception.SMPNotFoundException)6 ESuccess (com.helger.commons.state.ESuccess)5 IDocumentTypeIdentifier (com.helger.peppolid.IDocumentTypeIdentifier)5 ISMPServiceInformationManager (com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager)5 IUser (com.helger.photon.security.user.IUser)5 Map (java.util.Map)5 ReturnsMutableObject (com.helger.commons.annotation.ReturnsMutableObject)4 CallbackList (com.helger.commons.callback.CallbackList)4 CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)4 ICommonsList (com.helger.commons.collection.impl.ICommonsList)4 MutableBoolean (com.helger.commons.mutable.MutableBoolean)4