test_class.declarator: accountManager
test_class.modifier: @Mock
      protected
test_class.original_string: @Mock
      protected AccountManager accountManager;
test_class.type: AccountManager
test_class.var_name: accountManager
test_class.declarator: paramProcessWorker
test_class.modifier: protected
test_class.original_string: protected ParamProcessWorker paramProcessWorker;
test_class.type: ParamProcessWorker
test_class.var_name: paramProcessWorker
test_class.file: server/src/test/java/com/cloud/api/dispatch/ParamProcessWorkerTest.java
test_class.identifier: ParamProcessWorkerTest
test_case.body: @Test
      public void processParameters() {
          final HashMap<String, String> params = new HashMap<String, String>();
          params.put("strparam1", "foo");
          params.put("intparam1", "100");
          params.put("boolparam1", "true");
          params.put("doubleparam1", "11.89");
          final TestCmd cmd = new TestCmd();
          paramProcessWorker.processParameters(cmd, params);
          Assert.assertEquals("foo", cmd.strparam1);
          Assert.assertEquals(100, cmd.intparam1);
          Assert.assertTrue(Double.compare(cmd.doubleparam1, 11.89) == 0);
      }
test_case.class_method_signature: ParamProcessWorkerTest.processParameters()
test_case.full_signature: @Test public void processParameters()
test_case.identifier: processParameters
test_case.invocations: put put put put processParameters assertEquals assertEquals assertTrue compare
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void processParameters()
focal_class.declarator: s_logger = LoggerFactory.getLogger(ParamProcessWorker.class.getName())
focal_class.modifier: private static final
focal_class.original_string: private static final Logger s_logger = LoggerFactory.getLogger(ParamProcessWorker.class.getName());
focal_class.type: Logger
focal_class.var_name: s_logger
focal_class.declarator: inputFormat = new SimpleDateFormat("yyyy-MM-dd")
focal_class.modifier: public final
focal_class.original_string: public final DateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd");
focal_class.type: DateFormat
focal_class.var_name: inputFormat
focal_class.declarator: newInputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
focal_class.modifier: public final
focal_class.original_string: public final DateFormat newInputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
focal_class.type: DateFormat
focal_class.var_name: newInputFormat
focal_class.declarator: _accountMgr
focal_class.modifier: @Inject
      protected
focal_class.original_string: @Inject
      protected AccountManager _accountMgr;
focal_class.type: AccountManager
focal_class.var_name: _accountMgr
focal_class.declarator: _entityMgr
focal_class.modifier: @Inject
      protected
focal_class.original_string: @Inject
      protected EntityManager _entityMgr;
focal_class.type: EntityManager
focal_class.var_name: _entityMgr
focal_class.declarator: _secChecker
focal_class.original_string: List<SecurityChecker> _secChecker;
focal_class.type: List<SecurityChecker>
focal_class.var_name: _secChecker
focal_class.file: server/src/main/java/com/cloud/api/dispatch/ParamProcessWorker.java
focal_class.identifier: ParamProcessWorker
focal_class.interfaces: implements DispatchWorker
focal_class.class_method_signature: ParamProcessWorker.getSecChecker()
focal_class.full_signature: public List<SecurityChecker> getSecChecker()
focal_class.identifier: getSecChecker
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.return: List<SecurityChecker>
focal_class.signature: List<SecurityChecker> getSecChecker()
focal_class.class_method_signature: ParamProcessWorker.setSecChecker(List<SecurityChecker> secChecker)
focal_class.full_signature: @Inject public void setSecChecker(List<SecurityChecker> secChecker)
focal_class.identifier: setSecChecker
focal_class.modifiers: @Inject public
focal_class.parameters: (List<SecurityChecker> secChecker)
focal_class.return: void
focal_class.signature: void setSecChecker(List<SecurityChecker> secChecker)
focal_class.class_method_signature: ParamProcessWorker.handle(final DispatchTask task)
focal_class.full_signature: @Override public void handle(final DispatchTask task)
focal_class.identifier: handle
focal_class.modifiers: @Override public
focal_class.parameters: (final DispatchTask task)
focal_class.return: void
focal_class.signature: void handle(final DispatchTask task)
focal_class.class_method_signature: ParamProcessWorker.processParameters(final BaseCmd cmd, final Map params)
focal_class.full_signature: @SuppressWarnings({"unchecked", "rawtypes"}) public void processParameters(final BaseCmd cmd, final Map params)
focal_class.identifier: processParameters
focal_class.modifiers: @SuppressWarnings({"unchecked", "rawtypes"}) public
focal_class.parameters: (final BaseCmd cmd, final Map params)
focal_class.return: void
focal_class.signature: void processParameters(final BaseCmd cmd, final Map params)
focal_class.class_method_signature: ParamProcessWorker.doAccessChecks(BaseCmd cmd, Map<Object, AccessType> entitiesToAccess)
focal_class.full_signature: private void doAccessChecks(BaseCmd cmd, Map<Object, AccessType> entitiesToAccess)
focal_class.identifier: doAccessChecks
focal_class.modifiers: private
focal_class.parameters: (BaseCmd cmd, Map<Object, AccessType> entitiesToAccess)
focal_class.return: void
focal_class.signature: void doAccessChecks(BaseCmd cmd, Map<Object, AccessType> entitiesToAccess)
focal_class.class_method_signature: ParamProcessWorker.setFieldValue(final Field field, final BaseCmd cmdObj, final Object paramObj, final Parameter annotation)
focal_class.full_signature: @SuppressWarnings({"unchecked", "rawtypes"}) private void setFieldValue(final Field field, final BaseCmd cmdObj, final Object paramObj, final Parameter annotation)
focal_class.identifier: setFieldValue
focal_class.modifiers: @SuppressWarnings({"unchecked", "rawtypes"}) private
focal_class.parameters: (final Field field, final BaseCmd cmdObj, final Object paramObj, final Parameter annotation)
focal_class.return: void
focal_class.signature: void setFieldValue(final Field field, final BaseCmd cmdObj, final Object paramObj, final Parameter annotation)
focal_class.class_method_signature: ParamProcessWorker.isObjInNewDateFormat(final String string)
focal_class.full_signature: private boolean isObjInNewDateFormat(final String string)
focal_class.identifier: isObjInNewDateFormat
focal_class.modifiers: private
focal_class.parameters: (final String string)
focal_class.return: boolean
focal_class.signature: boolean isObjInNewDateFormat(final String string)
focal_class.class_method_signature: ParamProcessWorker.messageDate(final Date date, final int hourOfDay, final int minute, final int second)
focal_class.full_signature: private Date messageDate(final Date date, final int hourOfDay, final int minute, final int second)
focal_class.identifier: messageDate
focal_class.modifiers: private
focal_class.parameters: (final Date date, final int hourOfDay, final int minute, final int second)
focal_class.return: Date
focal_class.signature: Date messageDate(final Date date, final int hourOfDay, final int minute, final int second)
focal_class.class_method_signature: ParamProcessWorker.translateUuidToInternalId(final String uuid, final Parameter annotation)
focal_class.full_signature: private Long translateUuidToInternalId(final String uuid, final Parameter annotation)
focal_class.identifier: translateUuidToInternalId
focal_class.modifiers: private
focal_class.parameters: (final String uuid, final Parameter annotation)
focal_class.return: Long
focal_class.signature: Long translateUuidToInternalId(final String uuid, final Parameter annotation)
focal_method.body: @SuppressWarnings({"unchecked", "rawtypes"})
      public void processParameters(final BaseCmd cmd, final Map params) {
          final Map<Object, AccessType> entitiesToAccess = new HashMap<Object, AccessType>();
  
          final List<Field> cmdFields = cmd.getParamFields();
  
          for (final Field field : cmdFields) {
              final Parameter parameterAnnotation = field.getAnnotation(Parameter.class);
              final Object paramObj = params.get(parameterAnnotation.name());
              if (paramObj == null) {
                  if (parameterAnnotation.required()) {
                      throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Unable to execute API command " +
                              cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8) +
                              " due to missing parameter " + parameterAnnotation.name());
                  }
                  continue;
              }
  
              // marshall the parameter into the correct type and set the field value
              try {
                  setFieldValue(field, cmd, paramObj, parameterAnnotation);
              } catch (final IllegalArgumentException argEx) {
                  if (s_logger.isDebugEnabled()) {
                      s_logger.debug("Unable to execute API command " + cmd.getCommandName() + " due to invalid value " + paramObj + " for parameter " +
                              parameterAnnotation.name());
                  }
                  throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Unable to execute API command " +
                          cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8) + " due to invalid value " + paramObj + " for parameter " +
                          parameterAnnotation.name());
              } catch (final ParseException parseEx) {
                  if (s_logger.isDebugEnabled()) {
                      s_logger.debug("Invalid date parameter " + paramObj + " passed to command " + cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8));
                  }
                  throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Unable to parse date " + paramObj + " for command " +
                          cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8) + ", please pass dates in the format mentioned in the api documentation");
              } catch (final InvalidParameterValueException invEx) {
                  throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Unable to execute API command " +
                          cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8) + " due to invalid value. " + invEx.getMessage());
              } catch (final CloudRuntimeException cloudEx) {
                  s_logger.error("CloudRuntimeException", cloudEx);
                  // FIXME: Better error message? This only happens if the API command is not executable, which typically
                  //means
                  // there was
                  // and IllegalAccessException setting one of the parameters.
                  throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Internal error executing API command " +
                          cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8));
              }
  
              //check access on the resource this field points to
              try {
                  final ACL checkAccess = field.getAnnotation(ACL.class);
                  final CommandType fieldType = parameterAnnotation.type();
  
                  if (checkAccess != null) {
                      // Verify that caller can perform actions in behalf of vm
                      // owner acumulate all Controlled Entities together.
                      // parse the array of resource types and in case of map
                      // check access on key or value or both as specified in @acl
                      // implement external dao for classes that need findByName
                      // for maps, specify access to be checkd on key or value.
                      // Find the controlled entity DBid by uuid
  
                      if (parameterAnnotation.entityType() != null && parameterAnnotation.entityType().length > 0
                              && parameterAnnotation.entityType()[0].getAnnotation(EntityReference.class) != null) {
                          final Class<?>[] entityList = parameterAnnotation.entityType()[0].getAnnotation(EntityReference.class).value();
  
                          // Check if the parameter type is a single
                          // Id or list of id's/name's
                          switch (fieldType) {
                          case LIST:
                              final CommandType listType = parameterAnnotation.collectionType();
                              switch (listType) {
                              case LONG:
                              case UUID:
                                  final List<Long> listParam = (List<Long>) field.get(cmd);
                                  for (final Long entityId : listParam) {
                                      for (final Class entity : entityList) {
                                          final Object entityObj = _entityMgr.findById(entity, entityId);
                                          if(entityObj != null){
                                              entitiesToAccess.put(entityObj, checkAccess.accessType());
                                              break;
                                          }
                                      }
                                  }
                                  break;
                                  /*
                                   * case STRING: List<String> listParam = new
                                   * ArrayList<String>(); listParam =
                                   * (List)field.get(cmd); for(String entityName:
                                   * listParam){ ControlledEntity entityObj =
                                   * (ControlledEntity )daoClassInstance(entityId);
                                   * entitiesToAccess.add(entityObj); } break;
                                   */
                              default:
                                  break;
                              }
                              break;
                          case LONG:
                          case UUID:
                              for (final Class entity : entityList) {
                                  final Object entityObj = _entityMgr.findById(entity, (Long) field.get(cmd));
                                  if(entityObj != null){
                                      entitiesToAccess.put(entityObj, checkAccess.accessType());
                                      break;
                                  }
                              }
                              break;
                          default:
                              break;
                          }
                      }
                  }
  
              } catch (final IllegalArgumentException e) {
                  s_logger.error("Error initializing command " + cmd.getCommandName() + ", field " + field.getName() + " is not accessible.");
                  throw new CloudRuntimeException("Internal error initializing parameters for command " + cmd.getCommandName() + " [field " + field.getName() +
                          " is not accessible]");
              } catch (final IllegalAccessException e) {
                  s_logger.error("Error initializing command " + cmd.getCommandName() + ", field " + field.getName() + " is not accessible.");
                  throw new CloudRuntimeException("Internal error initializing parameters for command " + cmd.getCommandName() + " [field " + field.getName() +
                          " is not accessible]");
              }
  
          }
  
          doAccessChecks(cmd, entitiesToAccess);
      }
focal_method.class_method_signature: ParamProcessWorker.processParameters(final BaseCmd cmd, final Map params)
focal_method.full_signature: @SuppressWarnings({"unchecked", "rawtypes"}) public void processParameters(final BaseCmd cmd, final Map params)
focal_method.identifier: processParameters
focal_method.invocations: getParamFields getAnnotation get name required substring getCommandName length getCommandName name setFieldValue isDebugEnabled debug getCommandName name substring getCommandName length getCommandName name isDebugEnabled debug substring getCommandName length getCommandName substring getCommandName length getCommandName substring getCommandName length getCommandName getMessage error substring getCommandName length getCommandName getAnnotation type entityType entityType getAnnotation entityType value getAnnotation entityType collectionType get findById put accessType findById get put accessType error getCommandName getName getCommandName getName error getCommandName getName getCommandName getName doAccessChecks
focal_method.modifiers: @SuppressWarnings({"unchecked", "rawtypes"}) public
focal_method.parameters: (final BaseCmd cmd, final Map params)
focal_method.return: void
focal_method.signature: void processParameters(final BaseCmd cmd, final Map params)