Example usage for java.util EnumMap put

List of usage examples for java.util EnumMap put

Introduction

In this page you can find the example usage for java.util EnumMap put.

Prototype

public V put(K key, V value) 

Source Link

Document

Associates the specified value with the specified key in this map.

Usage

From source file:org.apache.hadoop.hbase.io.hfile.TestCacheOnWrite.java

private void readStoreFile(boolean useTags) throws IOException {
    AbstractHFileReader reader;/*from   ww  w.j a v a 2s  .co m*/
    if (useTags) {
        reader = (HFileReaderV3) HFile.createReader(fs, storeFilePath, cacheConf, conf);
    } else {
        reader = (HFileReaderV2) HFile.createReader(fs, storeFilePath, cacheConf, conf);
    }
    LOG.info("HFile information: " + reader);
    final boolean cacheBlocks = false;
    final boolean pread = false;
    HFileScanner scanner = reader.getScanner(cacheBlocks, pread);
    assertTrue(testDescription, scanner.seekTo());

    long offset = 0;
    HFileBlock prevBlock = null;
    EnumMap<BlockType, Integer> blockCountByType = new EnumMap<BlockType, Integer>(BlockType.class);

    DataBlockEncoding encodingInCache = encoderType.getEncoder().getDataBlockEncoding();
    while (offset < reader.getTrailer().getLoadOnOpenDataOffset()) {
        long onDiskSize = -1;
        if (prevBlock != null) {
            onDiskSize = prevBlock.getNextBlockOnDiskSizeWithHeader();
        }
        // Flags: don't cache the block, use pread, this is not a compaction.
        // Also, pass null for expected block type to avoid checking it.
        HFileBlock block = reader.readBlock(offset, onDiskSize, false, true, false, true, null,
                encodingInCache);
        BlockCacheKey blockCacheKey = new BlockCacheKey(reader.getName(), offset);
        boolean isCached = blockCache.getBlock(blockCacheKey, true, false, true) != null;
        boolean shouldBeCached = cowType.shouldBeCached(block.getBlockType());
        if (shouldBeCached != isCached) {
            throw new AssertionError("shouldBeCached: " + shouldBeCached + "\n" + "isCached: " + isCached + "\n"
                    + "Test description: " + testDescription + "\n" + "block: " + block + "\n"
                    + "encodingInCache: " + encodingInCache + "\n" + "blockCacheKey: " + blockCacheKey);
        }
        prevBlock = block;
        offset += block.getOnDiskSizeWithHeader();
        BlockType bt = block.getBlockType();
        Integer count = blockCountByType.get(bt);
        blockCountByType.put(bt, (count == null ? 0 : count) + 1);
    }

    LOG.info("Block count by type: " + blockCountByType);
    String countByType = blockCountByType.toString();
    BlockType cachedDataBlockType = encoderType.encode ? BlockType.ENCODED_DATA : BlockType.DATA;
    if (useTags) {
        assertEquals("{" + cachedDataBlockType + "=1550, LEAF_INDEX=173, BLOOM_CHUNK=9, INTERMEDIATE_INDEX=20}",
                countByType);
    } else {
        assertEquals("{" + cachedDataBlockType + "=1379, LEAF_INDEX=154, BLOOM_CHUNK=9, INTERMEDIATE_INDEX=18}",
                countByType);
    }
    reader.close();
}

From source file:com.gemstone.gemfire.cache.hdfs.internal.hoplog.HdfsSortedOplogOrganizer.java

/**
 * store cardinality information in metadata
 * @param localHLL the hll estimate for this hoplog only
 *//*from  w  ww.j  a v  a  2  s .  co  m*/
private EnumMap<Meta, byte[]> buildMetaData(ICardinality localHLL) throws IOException {
    EnumMap<Meta, byte[]> map = new EnumMap<Hoplog.Meta, byte[]>(Meta.class);
    map.put(Meta.LOCAL_CARDINALITY_ESTIMATE_V2, localHLL.getBytes());
    return map;
}

From source file:ru.orangesoftware.financisto2.db.DatabaseAdapter.java

public EnumMap<SystemAttribute, String> getSystemAttributesForTransaction(long transactionId) {
    Cursor c = db()/*from  w ww.j ava  2  s  . c  o  m*/
            .query(TRANSACTION_ATTRIBUTE_TABLE, TransactionAttributeColumns.NORMAL_PROJECTION,
                    TransactionAttributeColumns.TRANSACTION_ID + "=? AND "
                            + TransactionAttributeColumns.ATTRIBUTE_ID + "<0",
                    new String[] { String.valueOf(transactionId) }, null, null, null);
    try {
        EnumMap<SystemAttribute, String> attributes = new EnumMap<SystemAttribute, String>(
                SystemAttribute.class);
        while (c.moveToNext()) {
            long attributeId = c.getLong(TransactionAttributeColumns.Indicies.ATTRIBUTE_ID);
            String value = c.getString(TransactionAttributeColumns.Indicies.VALUE);
            attributes.put(SystemAttribute.forId(attributeId), value);
        }
        return attributes;
    } finally {
        c.close();
    }
}

From source file:org.openecomp.sdc.be.components.impl.ServiceBusinessLogic.java

private void createAudit(User user, AuditingActionEnum auditAction, String comment, Service component,
        ResponseFormat responseFormat, EnumMap<AuditingFieldsKeysEnum, Object> auditingFields) {
    log.debug("audit before sending response");
    auditingFields.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_COMMENT, comment);
    componentsUtils.auditComponent(responseFormat, user, component, null, null, auditAction,
            ComponentTypeEnum.SERVICE, auditingFields);
}

From source file:org.openecomp.sdc.be.components.impl.ServiceBusinessLogic.java

private void createAudit(User user, AuditingActionEnum auditAction, String comment, Service component,
        String prevState, String prevVersion, ResponseFormat responseFormat,
        EnumMap<AuditingFieldsKeysEnum, Object> auditingFields) {
    log.debug("audit before sending response");
    auditingFields.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_COMMENT, comment);
    componentsUtils.auditComponent(responseFormat, user, component, prevState, prevVersion, auditAction,
            ComponentTypeEnum.SERVICE, auditingFields);
}

From source file:org.openecomp.sdc.be.components.impl.ServiceBusinessLogic.java

private void createAudit(User user, AuditingActionEnum auditAction, String comment, Service component,
        ResponseFormat responseFormat) {
    EnumMap<AuditingFieldsKeysEnum, Object> auditingFields = new EnumMap<AuditingFieldsKeysEnum, Object>(
            AuditingFieldsKeysEnum.class);
    auditingFields.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_DCURR_STATUS,
            component.getDistributionStatus().name());
    auditingFields.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_DPREV_STATUS,
            component.getDistributionStatus().name());
    createAudit(user, auditAction, comment, component, component.getLifecycleState().name(),
            component.getVersion(), responseFormat, auditingFields);
}

From source file:org.roda.core.index.utils.SolrUtils.java

private static Permissions getPermissions(SolrDocument doc) {
    Permissions permissions = new Permissions();

    EnumMap<PermissionType, Set<String>> userPermissions = new EnumMap<>(PermissionType.class);

    for (PermissionType type : PermissionType.values()) {
        String key = RodaConstants.INDEX_PERMISSION_USERS_PREFIX + type;
        Set<String> users = new HashSet<>();
        users.addAll(objectToListString(doc.get(key)));
        userPermissions.put(type, users);
    }/*from  w ww  . ja  va 2s  . c om*/

    EnumMap<PermissionType, Set<String>> groupPermissions = new EnumMap<>(PermissionType.class);

    for (PermissionType type : PermissionType.values()) {
        String key = RodaConstants.INDEX_PERMISSION_GROUPS_PREFIX + type;
        Set<String> groups = new HashSet<>();
        groups.addAll(objectToListString(doc.get(key)));
        groupPermissions.put(type, groups);
    }

    permissions.setUsers(userPermissions);
    permissions.setGroups(groupPermissions);
    return permissions;
}

From source file:org.openecomp.sdc.be.components.impl.ServiceBusinessLogic.java

public Either<Service, ResponseFormat> activateDistribution(String serviceId, String envName, User modifier,
        HttpServletRequest request) {//www.  j a v  a 2s  .  c o  m

    Either<User, ResponseFormat> eitherCreator = validateUserExists(modifier.getUserId(),
            "activate Distribution", false);
    if (eitherCreator.isRight()) {
        return Either.right(eitherCreator.right().value());
    }

    User user = eitherCreator.left().value();

    Either<Service, ResponseFormat> result = null;
    ResponseFormat response = null;
    Service updatedService = null;
    String did = ThreadLocalsHolder.getUuid();
    EnumMap<AuditingFieldsKeysEnum, Object> auditingFields = new EnumMap<AuditingFieldsKeysEnum, Object>(
            AuditingFieldsKeysEnum.class);
    auditingFields.put(AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_ID, did);
    // DE194021
    String configuredEnvName = ConfigurationManager.getConfigurationManager()
            .getDistributionEngineConfiguration().getEnvironments().get(0);
    if (configuredEnvName != null && false == envName.equals(configuredEnvName)) {
        log.trace("Update environment name to be {} instead of {}", configuredEnvName, envName);
        envName = configuredEnvName;
    }
    // DE194021

    ServletContext servletContext = request.getSession().getServletContext();
    boolean isDistributionEngineUp = getHealthCheckBL(servletContext)
            .isDistributionEngineUp(request.getSession().getServletContext()); // DE
    if (!isDistributionEngineUp) {
        BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeSystemError,
                "Distribution Engine is DOWN");
        BeEcompErrorManager.getInstance().logBeSystemError("Distribution Engine is DOWN");
        log.debug("Distribution Engine is DOWN");
        response = componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR);
        return Either.right(response);
    }

    Either<Service, StorageOperationStatus> serviceRes = serviceOperation.getService(serviceId);
    if (serviceRes.isRight()) {
        log.debug("failed retrieving service");
        response = componentsUtils.getResponseFormat(componentsUtils
                .convertFromStorageResponse(serviceRes.right().value(), ComponentTypeEnum.SERVICE), serviceId);
        componentsUtils.auditComponent(response, user, null, null, null,
                AuditingActionEnum.DISTRIBUTION_STATE_CHANGE_REQUEST, ComponentTypeEnum.SERVICE,
                auditingFields);
        return Either.right(response);
    }
    Service service = serviceRes.left().value();
    String dcurrStatus = service.getDistributionStatus().name();
    auditingFields.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_DPREV_STATUS, dcurrStatus);

    Either<INotificationData, StorageOperationStatus> readyForDistribution = distributionEngine
            .isReadyForDistribution(service, did, envName);
    if (readyForDistribution.isLeft()) {
        INotificationData notificationData = readyForDistribution.left().value();
        StorageOperationStatus notifyServiceResponse = distributionEngine.notifyService(did, service,
                notificationData, envName, user.getUserId(), user.getFullName());
        if (notifyServiceResponse == StorageOperationStatus.OK) {
            Either<Service, ResponseFormat> updateStateRes = updateDistributionStatusForActivation(service,
                    user, DistributionStatusEnum.DISTRIBUTED);
            if (updateStateRes.isLeft() && updateStateRes.left().value() != null) {
                updatedService = updateStateRes.left().value();
                dcurrStatus = updatedService.getDistributionStatus().name();
            } else {
                // The response is not relevant
                updatedService = service;
            }
            ASDCKpiApi.countActivatedDistribution();
            response = componentsUtils.getResponseFormat(ActionStatus.OK);
            result = Either.left(updatedService);
        } else {
            BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeSystemError,
                    "Activate Distribution - send notification");
            BeEcompErrorManager.getInstance().logBeSystemError("Activate Distribution - send notification");
            log.debug("distributionEngine.notifyService response is: {}", notifyServiceResponse);
            response = componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR);
            result = Either.right(response);
        }
    } else {
        StorageOperationStatus distEngineValidationResponse = readyForDistribution.right().value();
        response = componentsUtils.getResponseFormatByDE(
                componentsUtils.convertFromStorageResponse(distEngineValidationResponse), service.getName(),
                envName);
        result = Either.right(response);
    }
    auditingFields.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_DCURR_STATUS, dcurrStatus);
    componentsUtils.auditComponent(response, user, service, null, null,
            AuditingActionEnum.DISTRIBUTION_STATE_CHANGE_REQUEST, ComponentTypeEnum.SERVICE, auditingFields);
    return result;
}

From source file:org.openecomp.sdc.be.components.impl.ServiceBusinessLogic.java

public Either<Service, ResponseFormat> changeServiceDistributionState(String serviceId, String state,
        LifecycleChangeInfoWithAction commentObj, User user) {

    Either<User, ResponseFormat> resp = validateUserExists(user.getUserId(),
            "change Service Distribution State", false);
    if (resp.isRight()) {
        return Either.right(resp.right().value());
    }//ww w .ja v  a  2 s.  c om

    log.debug("check request state");
    Either<DistributionTransitionEnum, ResponseFormat> validateEnum = validateTransitionEnum(state, user);
    if (validateEnum.isRight()) {
        return Either.right(validateEnum.right().value());
    }
    DistributionTransitionEnum distributionTransition = validateEnum.left().value();
    AuditingActionEnum auditAction = (distributionTransition == DistributionTransitionEnum.APPROVE
            ? AuditingActionEnum.DISTRIBUTION_STATE_CHANGE_APPROV
            : AuditingActionEnum.DISTRIBUTION_STATE_CHANGE_REJECT);
    Either<String, ResponseFormat> commentResponse = validateComment(commentObj, user, auditAction);
    if (commentResponse.isRight()) {
        return Either.right(commentResponse.right().value());
    }
    String comment = commentResponse.left().value();

    Either<Service, ResponseFormat> validateService = validateServiceDistributionChange(user, serviceId,
            auditAction, comment);
    if (validateService.isRight()) {
        return Either.right(validateService.right().value());
    }
    Service service = validateService.left().value();
    DistributionStatusEnum initState = service.getDistributionStatus();

    Either<User, ResponseFormat> validateUser = validateUserDistributionChange(user, service, auditAction,
            comment);
    if (validateUser.isRight()) {
        return Either.right(validateUser.right().value());
    }
    user = validateUser.left().value();

    // lock resource
    /*
     * StorageOperationStatus lockResult = graphLockOperation.lockComponent(serviceId, NodeTypeEnum.Service); if (!lockResult.equals(StorageOperationStatus.OK)) { BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.
     * BeFailedLockObjectError, "ChangeServiceDistributionState"); log.debug("Failed to lock service {} error - {}", serviceId, lockResult); ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR,
     * service.getVersion(), service.getServiceName());
     * 
     * createAudit(user, auditAction, comment, service, responseFormat); return Either.right(componentsUtils.getResponseFormat(ActionStatus. GENERAL_ERROR)); }
     */
    Either<Boolean, ResponseFormat> lockResult = lockComponent(serviceId, service,
            "ChangeServiceDistributionState");
    if (lockResult.isRight()) {
        ResponseFormat responseFormat = lockResult.right().value();
        createAudit(user, auditAction, comment, service, responseFormat);
        return Either.right(responseFormat);
    }

    try {

        DistributionStatusEnum newState;
        if (distributionTransition == DistributionTransitionEnum.APPROVE) {
            newState = DistributionStatusEnum.DISTRIBUTION_APPROVED;
        } else {
            newState = DistributionStatusEnum.DISTRIBUTION_REJECTED;
        }
        Either<Service, StorageOperationStatus> result = serviceOperation.updateDestributionStatus(service,
                user, newState);
        if (result.isRight()) {
            titanGenericDao.rollback();
            BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeSystemError,
                    "ChangeServiceDistributionState");
            BeEcompErrorManager.getInstance().logBeSystemError("ChangeServiceDistributionState");
            log.debug("service {} is  change destribuation status failed", service.getUniqueId());
            ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR,
                    service.getVersion(), service.getName());
            createAudit(user, auditAction, comment, service, responseFormat);
            return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
        }
        titanGenericDao.commit();
        Service updatedService = result.left().value();
        ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.OK);
        EnumMap<AuditingFieldsKeysEnum, Object> auditingFields = new EnumMap<AuditingFieldsKeysEnum, Object>(
                AuditingFieldsKeysEnum.class);
        auditingFields.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_DCURR_STATUS,
                updatedService.getDistributionStatus().name());
        auditingFields.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_DPREV_STATUS, initState.name());
        createAudit(user, auditAction, comment, updatedService, responseFormat, auditingFields);
        return Either.left(result.left().value());

    } finally {
        graphLockOperation.unlockComponent(serviceId, NodeTypeEnum.Service);
    }

}

From source file:tasly.greathealth.oms.inventory.facades.DefaultItemQuantityFacade.java

@Override
public boolean updateItemQuantity() {
    EnumMap<HandleReturn, Object> handleReturn = new EnumMap<HandleReturn, Object>(HandleReturn.class);
    boolean updateStatus = true;
    final List<String> errorSkus = new ArrayList<>();
    final List<ItemInfoData> itemInfoDatas = itemInfoService.getAll();
    if (itemInfoDatas != null && itemInfoDatas.size() > 0) {
        for (int i = 0; i < itemInfoDatas.size(); i++) {
            final String sku = itemInfoDatas.get(i).getSku();
            final int totalNumber = itemInfoDatas.get(i).getQuantity();
            final int flag = itemInfoDatas.get(i).getStockManageFlag();

            final Date nowDay = new Date();
            final SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssZ");
            final String nowDate = sdf.format(nowDay);
            final String nowDateString = nowDate.substring(0, 8);
            final String modifyDay = itemInfoDatas.get(i).getExt1();
            String modifyDayString = null;
            if (StringUtils.isEmpty(modifyDay)) {
                modifyDayString = "";
            } else {
                modifyDayString = modifyDay.substring(0, 8);
            }/*ww w.j  a va2 s  . c o m*/
            if ("".equals(modifyDayString) || nowDateString.equals(modifyDayString) || flag == 0) {
                final List<TaslyItemLocationData> checkTaslyItemLocationDatas = taslyItemLocationService
                        .getByItemID(sku);
                if (checkTaslyItemLocationDatas == null || checkTaslyItemLocationDatas.size() == 0) {
                    omsLOG.error("sku:" + sku + ",no ItemLocation data!");
                    continue;
                } else {
                    try {
                        handleReturn = itemQuantityService.handleUpdateMethod(checkTaslyItemLocationDatas, sku,
                                flag, totalNumber);
                    } catch (final Exception e) {
                        omsLOG.error("handle sku:" + sku + " failed and error is " + e);
                        handleReturn.put(HandleReturn.handleStatus, false);
                    }
                    if ((boolean) handleReturn.get(HandleReturn.handleStatus)) {
                        if ((boolean) handleReturn.get(HandleReturn.errorStatus)) {
                            errorSkus.add(sku);
                        }
                        try {
                            updateStatus = itemQuantityService.updateMethod(sku, flag,
                                    (int) handleReturn.get(HandleReturn.availableNumber));
                            if (flag == 0 && updateStatus) {
                                omsLOG.debug("sku:" + sku + ",flag=0 allocated ok!");
                            } else if (flag == 1 && updateStatus) {
                                omsLOG.debug("sku:" + sku + ",flag=1 allocated ok!");
                            }
                        } catch (final Exception e) {
                            omsLOG.error("update sku:" + sku + " failed and error is " + e);
                        }
                    } else {
                        continue;
                    }
                }
            } else if (!nowDateString.equals(modifyDayString) && flag == 1) {
                omsLOG.error("sku:" + sku + ",modifyTime:" + modifyDayString + ",nowday:" + nowDateString
                        + ".The modifyTime not equal currentdate,current sku skip allocated");
                continue;
            }
        }
        if (errorSkus.size() > 0) {
            final StringBuffer skulist = new StringBuffer();
            for (final String errorSku : errorSkus) {
                skulist.append(errorSku + ",");
            }
            omsSkuLog.error("???SKU" + skulist.toString());
        }
        return true;
    } else {
        omsLOG.error("get iteminfos failed!");
        return false;
    }
}