Search in sources :

Example 1 with OperationType

use of org.broadleafcommerce.common.presentation.client.OperationType in project BroadleafCommerce by BroadleafCommerce.

the class AdminUserCustomPersistenceHandler method remove.

@Override
public void remove(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
    Entity entity = persistencePackage.getEntity();
    String idValue = entity.findProperty("id").getValue();
    String userLoginToRemove = entity.findProperty("login") == null ? null : entity.findProperty("login").getValue();
    AdminUser persistentAdminUser = adminRemoteSecurityService.getPersistentAdminUser();
    if (persistentAdminUser != null && persistentAdminUser.getLogin() != null && userLoginToRemove != null) {
        if (persistentAdminUser.getLogin().equals(userLoginToRemove)) {
            throw new ValidationException(entity, "admin.cantDeleteCurrentUserError");
        }
    }
    if (idValue != null) {
        Long id = Long.parseLong(idValue);
        AdminUser adminInstance = adminSecurityService.readAdminUserById(id);
        // Check if Status was Weaved in
        if (Status.class.isAssignableFrom(adminInstance.getClass())) {
            ((Status) adminInstance).setArchived('Y');
            adminSecurityService.saveAdminUser(adminInstance);
            return;
        }
    }
    OperationType removeType = persistencePackage.getPersistencePerspective().getOperationTypes().getRemoveType();
    helper.getCompatibleModule(removeType).remove(persistencePackage);
}
Also used : Status(org.broadleafcommerce.common.persistence.Status) Entity(org.broadleafcommerce.openadmin.dto.Entity) ValidationException(org.broadleafcommerce.openadmin.server.service.ValidationException) AdminUser(org.broadleafcommerce.openadmin.server.security.domain.AdminUser) EntityOperationType(org.broadleafcommerce.openadmin.server.security.remote.EntityOperationType) OperationType(org.broadleafcommerce.common.presentation.client.OperationType)

Example 2 with OperationType

use of org.broadleafcommerce.common.presentation.client.OperationType in project BroadleafCommerce by BroadleafCommerce.

the class OfferCustomPersistenceHandler method update.

@Override
public Entity update(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
    Entity entity = persistencePackage.getEntity();
    // This can't be on a validator since the field is dynamically added with JavaScript
    Property isMultiTierOffer = entity.findProperty(IS_TIERED_OFFER);
    if (isMultiTierOffer != null) {
        String multiTierValue = isMultiTierOffer.getValue();
        if ("false".equalsIgnoreCase(multiTierValue)) {
            Property offerValue = entity.findProperty(OFFER_VALUE);
            if (offerValue != null) {
                String value = offerValue.getValue();
                if (value == null || "null".equalsIgnoreCase(value)) {
                    entity.addValidationError(OFFER_VALUE, "requiredFieldMessage");
                }
            }
        }
    }
    Property qualifiersCanBeQualifiers = entity.findProperty(QUALIFIERS_CAN_BE_QUALIFIERS);
    if (qualifiersCanBeQualifiers != null) {
        qualifiersCanBeQualifiers.setIsDirty(true);
    }
    Property qualifiersCanBeTargets = entity.findProperty(QUALIFIERS_CAN_BE_TARGETS);
    if (qualifiersCanBeTargets != null) {
        qualifiersCanBeTargets.setIsDirty(true);
    }
    Property offerItemQualifierRuleType = buildOfferItemQualifierRuleTypeProperty(qualifiersCanBeQualifiers, qualifiersCanBeTargets);
    entity.addProperty(offerItemQualifierRuleType);
    Property stackable = entity.findProperty(STACKABLE);
    if (stackable != null) {
        stackable.setIsDirty(true);
    }
    Property offerItemTargetRuleType = buildOfferItemTargetRuleTypeProperty(stackable);
    entity.addProperty(offerItemTargetRuleType);
    OperationType updateType = persistencePackage.getPersistencePerspective().getOperationTypes().getUpdateType();
    return helper.getCompatibleModule(updateType).update(persistencePackage);
}
Also used : Entity(org.broadleafcommerce.openadmin.dto.Entity) OperationType(org.broadleafcommerce.common.presentation.client.OperationType) Property(org.broadleafcommerce.openadmin.dto.Property)

Example 3 with OperationType

use of org.broadleafcommerce.common.presentation.client.OperationType in project BroadleafCommerce by BroadleafCommerce.

the class CustomerPaymentCustomPersistenceHandler method fetch.

@Override
public DynamicResultSet fetch(PersistencePackage persistencePackage, CriteriaTransferObject cto, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
    OperationType fetchType = persistencePackage.getPersistencePerspective().getOperationTypes().getFetchType();
    PersistenceModule persistenceModule = helper.getCompatibleModule(fetchType);
    DynamicResultSet drs = persistenceModule.fetch(persistencePackage, cto);
    for (Entity entity : drs.getRecords()) {
        Property customerPaymentId = entity.findProperty("id");
        if (customerPaymentId != null) {
            CustomerPayment customerPayment = customerPaymentService.readCustomerPaymentById(Long.parseLong(customerPaymentId.getValue()));
            if (customerPayment != null) {
                String savedPaymentDisplayValue = buildSavedPaymentDisplayValue(customerPayment);
                Property derivedLabel = new Property();
                derivedLabel.setName(SAVED_PAYMENT_INFO);
                derivedLabel.setValue(savedPaymentDisplayValue);
                entity.addProperty(derivedLabel);
            }
        }
    }
    return drs;
}
Also used : Entity(org.broadleafcommerce.openadmin.dto.Entity) CustomerPayment(org.broadleafcommerce.profile.core.domain.CustomerPayment) OperationType(org.broadleafcommerce.common.presentation.client.OperationType) PersistenceModule(org.broadleafcommerce.openadmin.server.service.persistence.module.PersistenceModule) DynamicResultSet(org.broadleafcommerce.openadmin.dto.DynamicResultSet) Property(org.broadleafcommerce.openadmin.dto.Property)

Aggregations

OperationType (org.broadleafcommerce.common.presentation.client.OperationType)3 Entity (org.broadleafcommerce.openadmin.dto.Entity)3 Property (org.broadleafcommerce.openadmin.dto.Property)2 Status (org.broadleafcommerce.common.persistence.Status)1 DynamicResultSet (org.broadleafcommerce.openadmin.dto.DynamicResultSet)1 AdminUser (org.broadleafcommerce.openadmin.server.security.domain.AdminUser)1 EntityOperationType (org.broadleafcommerce.openadmin.server.security.remote.EntityOperationType)1 ValidationException (org.broadleafcommerce.openadmin.server.service.ValidationException)1 PersistenceModule (org.broadleafcommerce.openadmin.server.service.persistence.module.PersistenceModule)1 CustomerPayment (org.broadleafcommerce.profile.core.domain.CustomerPayment)1