public static String validateAssetKey(AssetKey assetKey) {
   if (assetKey != null) {
     if (assetKey.getAssetId() == null || assetKey.getAssetName() == null) {
       return RepositoryServiceClientConstants.FAILURE;
     }
     return RepositoryServiceClientConstants.SUCCESS;
   }
   return RepositoryServiceClientConstants.FAILURE;
 }
  /**
   * Helper method to validate the asset basic and extended info
   *
   * @return
   */
  private AssetInfo validateAsset(String assetId) {
    // now, i search the service to get all its related objects
    RepositoryServiceProviderImpl provider = new RepositoryServiceProviderImpl();

    GetAssetInfoRequest request = new GetAssetInfoRequest();
    AssetKey key = new AssetKey();
    key.setAssetId(assetId);
    request.setAssetKey(key);
    request.setAssetType("Service");

    GetAssetInfoResponse assetInfoResponse = provider.getAssetInfo(request);
    assertEquals(AckValue.SUCCESS, assetInfoResponse.getAck());
    assertEquals(null, assetInfoResponse.getErrorMessage());

    return assetInfoResponse.getAssetInfo();
  }
  private CreateCompleteAssetResponse createAsset() throws Exception {
    AssetKey key = new AssetKey();
    Library lib = new Library();
    lib.setLibraryName(libraryName);
    key.setLibrary(lib);
    key.setAssetName(assetName);

    BasicAssetInfo basicInfo = new BasicAssetInfo();
    basicInfo.setAssetKey(key);
    basicInfo.setAssetName(assetName);
    basicInfo.setAssetDescription(assetDesc);
    basicInfo.setAssetType("Service");

    ExtendedAssetInfo extendedInfo = new ExtendedAssetInfo();
    List<AttributeNameValue> attrs = extendedInfo.getAttribute();
    attrs.add(RSProviderUtil.newAttribute("namespace", libraryName));

    AssetLifeCycleInfo lifeCycleInfo = new AssetLifeCycleInfo();
    lifeCycleInfo.setDomainOwner("John Doe");
    lifeCycleInfo.setDomainType("Technical Owner");

    AssetInfo assetInfo = new AssetInfo();
    assetInfo.setBasicAssetInfo(basicInfo);
    assetInfo.setExtendedAssetInfo(extendedInfo);
    assetInfo.setAssetLifeCycleInfo(lifeCycleInfo);

    Artifact endpoint = new Artifact();
    endpoint.setArtifactName("ep-" + assetName);
    endpoint.setArtifactCategory("Endpoint");
    endpoint.setArtifactValueType(ArtifactValueType.URL);

    String endpointUrl = baseUrl + assetName;
    ArtifactInfo endpointInfo = new ArtifactInfo();
    endpointInfo.setArtifact(endpoint);
    endpointInfo.setArtifactDetail(endpointUrl.getBytes("UTF-8"));
    endpointInfo.setContentType("application/vnd.wso2.endpoint");

    List<ArtifactInfo> artifactList = assetInfo.getArtifactInfo();
    artifactList.add(endpointInfo);

    FlattenedRelationship relationship = new FlattenedRelationship();
    List<Relation> relationList = relationship.getRelatedAsset();
    relationList.add(
        new Relation() {
          {
            this.setSourceAsset(
                RSProviderUtil.completeAssetKey(
                    new AssetKey() {
                      {
                        this.setAssetId(resources[0]);
                      }
                    },
                    null,
                    null));
            this.setTargetAsset(
                RSProviderUtil.completeAssetKey(
                    new AssetKey() {
                      {
                        this.setAssetId(dstAssets[0]);
                      }
                    },
                    null,
                    null));
            this.setAssetRelationship("DependsOn");
          }
        });
    assetInfo.setFlattenedRelationship(relationship);

    CreateCompleteAssetRequest request = new CreateCompleteAssetRequest();
    request.setAssetInfo(assetInfo);

    RepositoryServiceProviderImpl provider = new RepositoryServiceProviderImpl();
    return provider.createCompleteAsset(request);
  }
  private UpdateAssetDependenciesResponse updateDependencies(String assetId) throws Exception {
    AssetKey key = new AssetKey();
    key.setAssetId(assetId);

    LockAssetRequest lockReq = new LockAssetRequest();
    lockReq.setAssetKey(key);

    RepositoryServiceProviderImpl provider = new RepositoryServiceProviderImpl();
    LockAssetResponse lockRes = provider.lockAsset(lockReq);
    assertEquals(AckValue.SUCCESS, lockRes.getAck());

    FlattenedRelationshipForUpdate relationship = new FlattenedRelationshipForUpdate();
    relationship.setDepth(1);
    relationship.setSourceAsset(key);
    List<RelationForUpdate> relationList = relationship.getRelatedAsset();
    relationList.add(
        new RelationForUpdate() {
          {
            this.setCurrentSourceAsset(
                RSProviderUtil.completeAssetKey(
                    new AssetKey() {
                      {
                        this.setAssetId(resources[0]);
                      }
                    },
                    null,
                    null));
            this.setCurrentTargetAsset(
                RSProviderUtil.completeAssetKey(
                    new AssetKey() {
                      {
                        this.setAssetId(dstAssets[0]);
                      }
                    },
                    null,
                    null));
            this.setNewRelation(
                new Relation() {
                  {
                    this.setSourceAsset(
                        RSProviderUtil.completeAssetKey(
                            new AssetKey() {
                              {
                                this.setAssetId(resources[0]);
                              }
                            },
                            null,
                            null));
                    this.setTargetAsset(
                        RSProviderUtil.completeAssetKey(
                            new AssetKey() {
                              {
                                this.setAssetId(dstAssets[1]);
                              }
                            },
                            null,
                            null));
                    this.setAssetRelationship("DependsOn");
                  }
                });
          }
        });

    UpdateAssetDependenciesRequest request = new UpdateAssetDependenciesRequest();
    request.setAssetKey(key);
    request.setFlattenedRelationshipForUpdate(relationship);
    request.setReplaceCurrent(true);

    return provider.updateAssetDependencies(request);
  }