Hi Shenavi,

As Danesh suggested can you check whether the following method works.

Registry registry = requestContext.getRegistry();
String resourcePath = requestContext.getResourcePath().getPath();

governanceArtifact =
GovernanceUtils.retrieveGovernanceArtifactByPath(requestContext.getSystemRegistry(),
resourcePath);

governanceArtifact.setAttribute("","");


Thanks!

Rajith


On Thu, Sep 29, 2016 at 9:31 AM, Danesh Kuruppu <dan...@wso2.com> wrote:

> Hi Shenavi,
>
> Did you try with the registry comes with requestContext as below.
> requestContext does have a registry, we can use that for registry
> operations
>
> requestContext.getRegistry()
>>
>
>
> Thanks
> Danesh
>
> On Thu, Sep 29, 2016 at 12:55 AM, Shenavi de Mel <shen...@wso2.com> wrote:
>
>> Hi All,
>>
>> I am trying to update an artifact created out of my custom API rxt in
>> greg inside the lifecycle executor class. Inside the lifecycle executer
>> class I need to modify the value of the field "implement_sandboxURL". When
>> i try to  update it using the java API it returns as a success but the
>> registry asset does not get updated with the value being passed in the
>> registry.
>>
>> Am I doing something wrong in how I am updating it? Your help would be
>> appreciated. Below is a block of code from inside the execution class which
>> corresponds to the update.
>>
>> {code}
>> Resource apiResource = requestContext.getResource();
>> String apiUUID = apiResource.getUUID();
>>
>> PrivilegedCarbonContext.startTenantFlow();
>> PrivilegedCarbonContext.getThreadLocalCarbonContext().setTen
>> antDomain(carbonContext.getTenantDomain());
>> PrivilegedCarbonContext.getThreadLocalCarbonContext().setTen
>> antId(carbonContext.getTenantId());
>>
>> *** Registry userRegistry = getUserRegistry();*
>> GenericArtifactManager manager = new GenericArtifactManager(userReg
>> istry,"api");
>> GenericArtifact apiGenericArtifact = manager.getGenericArtifact(apiUUID);
>> apiGenericArtifact.setAttribute("implement_sandboxURL","http
>> ://test.wso2.com");
>> manager.updateGenericArtifact(apiGenericArtifact);
>>
>> PrivilegedCarbonContext.endTenantFlow();
>>
>> {code}
>>
>>
>> *** Different methods tried to retrieve the registry instance*
>>
>> Method 1
>>
>> protected Registry getUserRegistry() throws RegistryException {
>>         CarbonContext carbonContext = PrivilegedCarbonContext.getThr
>> eadLocalCarbonContext();
>>         RegistryService registryService = (RegistryService)
>> carbonContext.getOSGiService(RegistryService.class, null);
>>         return registryService.getGovernanceUserRegistry("admin",
>> carbonContext.getTenantId());
>> }
>>
>> Method 2
>>
>> protected Registry getUserRegistry() {
>>         return (Registry)CarbonContext.getThr
>> eadLocalCarbonContext().getRegistry(RegistryType.USER_GOVERNANCE);
>> }
>>
>> Method 3
>>
>> protected Registry getUserRegistry() {
>>       ServiceDataHolder.getInstance().getTenantRegistryLoader().lo
>> adTenantRegistry(carbonContext.getTenantId());
>>      return 
>> ServiceDataHolder.getInstance().getRegistryService().getGovernanceUserRegistry("admin");
>>
>> }
>>
>> Am I missing something? What may be the reason the artifact does not get
>> updated? When i update using the edit option in the UI it works but not
>> through the code. Also i debugged in both cases and the flow was identical
>> as well.
>>
>> Thanks
>> Shenavi
>>
>> *Shenavi de Mel*
>> Software Engineer
>> WSO2 Inc: http://wso2.com
>> email: shen...@wso2.com
>> mobile: 0711644470
>>
>>
>
>
> --
>
> *Danesh Kuruppu*
> Senior Software Engineer | WSO2
>
> Email: dan...@wso2.com
> Mobile: +94 (77) 1690552
> Web: WSO2 Inc <https://wso2.com/signature>
>
>


-- 
Rajith Roshan
Software Engineer, WSO2 Inc.
Mobile: +94-72-642-8350 <%2B94-71-554-8430>
_______________________________________________
Dev mailing list
Dev@wso2.org
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to