2929import javax .inject .Inject ;
3030
3131import org .apache .cloudstack .api .ApiConstants ;
32+ import org .apache .cloudstack .api .BaseCmd ;
3233import org .apache .cloudstack .api .command .user .iso .DeleteIsoCmd ;
3334import org .apache .cloudstack .api .command .user .iso .GetUploadParamsForIsoCmd ;
3435import org .apache .cloudstack .api .command .user .iso .RegisterIsoCmd ;
@@ -469,7 +470,7 @@ public TemplateProfile prepare(RegisterTemplateCmd cmd) throws ResourceAllocatio
469470 /**
470471 * Prepare upload parameters internal method for templates and ISOs local upload
471472 */
472- private TemplateProfile prepareUploadParamsInternal (UploadParams params ) throws ResourceAllocationException {
473+ private TemplateProfile prepareUploadParamsInternal (BaseCmd cmd , UploadParams params ) throws ResourceAllocationException {
473474 //check if the caller can operate with the template owner
474475 Account caller = CallContext .current ().getCallingAccount ();
475476 Account owner = _accountMgr .getAccount (params .getTemplateOwnerId ());
@@ -490,17 +491,8 @@ private TemplateProfile prepareUploadParamsInternal(UploadParams params) throws
490491 StringUtils .join (Arrays .stream (HypervisorType .values ()).filter (h -> h != HypervisorType .None ).map (HypervisorType ::name ).toArray (), ", " )));
491492 }
492493
493- TemplateType templateType ;
494- if (params .getTemplateType () != null ) {
495- try {
496- templateType = TemplateType .valueOf (params .getTemplateType ().toUpperCase ());
497- } catch (IllegalArgumentException ex ) {
498- throw new InvalidParameterValueException (String .format ("Please specify a valid templatetype: %s" ,
499- org .apache .commons .lang3 .StringUtils .join ("," , TemplateType .values ())));
500- }
501- } else {
502- templateType = params .isRoutingType () ? TemplateType .ROUTING : TemplateType .USER ;
503- }
494+ TemplateType templateType = templateMgr .validateTemplateType (cmd , _accountMgr .isAdmin (caller .getAccountId ()),
495+ false , params .getHypervisorType ());
504496
505497 return prepare (params .isIso (), params .getUserId (), params .getName (), params .getDisplayText (), params .getArch (), params .getBits (),
506498 params .isPasswordEnabled (), params .requiresHVM (), params .getUrl (), params .isPublic (), params .isFeatured (),
@@ -531,7 +523,7 @@ public TemplateProfile prepare(GetUploadParamsForTemplateCmd cmd) throws Resourc
531523 cmd .getTemplateTag (), cmd .getEntityOwnerId (), cmd .getDetails (), BooleanUtils .toBoolean (cmd .isSshKeyEnabled ()),
532524 BooleanUtils .toBoolean (cmd .isDynamicallyScalable ()), BooleanUtils .toBoolean (cmd .isRoutingType ()), cmd .isDeployAsIs (),
533525 cmd .isForCks (), cmd .getTemplateType ());
534- return prepareUploadParamsInternal (params );
526+ return prepareUploadParamsInternal (cmd , params );
535527 }
536528
537529 @ Override
@@ -540,7 +532,7 @@ public TemplateProfile prepare(GetUploadParamsForIsoCmd cmd) throws ResourceAllo
540532 cmd .getDisplayText (), BooleanUtils .toBoolean (cmd .isPublic ()), BooleanUtils .toBoolean (cmd .isFeatured ()),
541533 BooleanUtils .toBoolean (cmd .isExtractable ()), cmd .getOsTypeId (),
542534 cmd .getZoneId (), BooleanUtils .toBoolean (cmd .isBootable ()), cmd .getEntityOwnerId ());
543- return prepareUploadParamsInternal (params );
535+ return prepareUploadParamsInternal (cmd , params );
544536 }
545537
546538 @ Override
0 commit comments