OperationDESCContextManagerImpl.java

package com.mycim.server.ctx.exec.manager.impl;

import com.fa.sesa.threadlocal.LocalContext;
import com.mycim.server.base.manager.NamedObjectManager;
import com.mycim.server.ctx.exec.manager.OperationDESCContextManager;
import com.mycim.server.ctx.manager.ContextValueManager;
import com.mycim.valueobject.ObjectList;
import com.mycim.valueobject.prp.ContextValue;
import com.mycim.valueobject.prp.OperationDESCContextValue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author Luopeng.Wang
 * @version 6.0.0
 * @date 2019/9/9
 **/

@Service
@Transactional
public class OperationDESCContextManagerImpl implements OperationDESCContextManager {

    @Autowired
    private ContextValueManager contextValueManager;

    @Autowired
    private NamedObjectManager namedObjectManager;


    @Override
    public ContextValue getOperationDESCContextValue(Long productRrn, Long processRrn, Integer processVersion,
                                                     Long routeRrn, Long operationRrn) {
        OperationDESCContextValue operationDESCContextValue = buildNewOperationDESCContextValueForProcess(productRrn,
                                                                                                          processRrn,
                                                                                                          processVersion,
                                                                                                          routeRrn,
                                                                                                          operationRrn);
        ContextValue contextValue = contextValueManager
                .getContextValue(operationDESCContextValue, LocalContext.getFacilityRrn());
        return contextValue;
    }


    public OperationDESCContextValue buildNewOperationDESCContextValue() {
        OperationDESCContextValue contextValue = new OperationDESCContextValue();
        contextValue.setContextRrn(namedObjectManager.getNamedObjectRrn(contextValue.getContextId(),
                                                                        LocalContext.getFacilityRrn(),
                                                                        ObjectList.CONTEXT_KEY));
        return contextValue;
    }

    private OperationDESCContextValue buildNewOperationDESCContextValueForProcess(Long productRrn, Long processRrn,
                                                                                  Integer processVersion, Long routeRrn,
                                                                                  Long operationRrn) {
        OperationDESCContextValue contextValue = buildNewOperationDESCContextValue();

        contextValue.setProductRrn(productRrn);
        contextValue.setProcessRrn(processRrn);
        contextValue.setProcessVersion(processVersion);
        contextValue.setRouteRrn(routeRrn);
        contextValue.setOperationRrn(operationRrn);
        return contextValue;
    }

}