Search in sources :

Example 1 with FilePolicyListRestRep

use of com.emc.storageos.model.file.policy.FilePolicyListRestRep in project coprhd-controller by CoprHD.

the class FilePolicyApiTest method testListFileSnapshotPolicies.

@Test
public void testListFileSnapshotPolicies() {
    FilePolicyListRestRep filePolicyListResp = rSys.path(FILE_POLICIES).get(FilePolicyListRestRep.class);
    Assert.assertNotNull(filePolicyListResp);
    List<NamedRelatedResourceRep> filePolicies = filePolicyListResp.getFilePolicies();
    for (Iterator<NamedRelatedResourceRep> iterator = filePolicies.iterator(); iterator.hasNext(); ) {
        NamedRelatedResourceRep namedRelatedResourceRep = iterator.next();
        if (namedRelatedResourceRep.getId().equals(createdFileSnapshotPolicyURI)) {
            Assert.assertTrue(true);
            return;
        }
    }
    Assert.assertTrue(false);
}
Also used : NamedRelatedResourceRep(com.emc.storageos.model.NamedRelatedResourceRep) FilePolicyListRestRep(com.emc.storageos.model.file.policy.FilePolicyListRestRep) Test(org.junit.Test)

Example 2 with FilePolicyListRestRep

use of com.emc.storageos.model.file.policy.FilePolicyListRestRep in project coprhd-controller by CoprHD.

the class FileProtectionPolicies method listJson.

@FlashException(value = "list", keep = true)
public static void listJson() {
    FilePolicyListRestRep viprSchedulePolicies = getViprClient().fileProtectionPolicies().listFilePolicies();
    List<ScheculePoliciesDataTable.FileProtectionPolicy> scheculePolicies = Lists.newArrayList();
    for (NamedRelatedResourceRep policy : viprSchedulePolicies.getFilePolicies()) {
        scheculePolicies.add(new ScheculePoliciesDataTable.FileProtectionPolicy(getViprClient().fileProtectionPolicies().getFilePolicy(policy.getId())));
    }
    renderJSON(DataTablesSupport.createJSON(scheculePolicies, params));
}
Also used : ScheculePoliciesDataTable(models.datatable.ScheculePoliciesDataTable) NamedRelatedResourceRep(com.emc.storageos.model.NamedRelatedResourceRep) FilePolicyListRestRep(com.emc.storageos.model.file.policy.FilePolicyListRestRep) FlashException(controllers.util.FlashException)

Example 3 with FilePolicyListRestRep

use of com.emc.storageos.model.file.policy.FilePolicyListRestRep in project coprhd-controller by CoprHD.

the class FileProvider method getAllFileSystemLevelPolicies.

private List<FilePolicyRestRep> getAllFileSystemLevelPolicies(AssetOptionsContext ctx) {
    ViPRCoreClient client = api(ctx);
    List<FilePolicyRestRep> fileSystemPolicies = new ArrayList<FilePolicyRestRep>();
    FilePolicyListRestRep policies = client.fileProtectionPolicies().listFilePolicies();
    if (policies != null && !policies.getFilePolicies().isEmpty()) {
        for (NamedRelatedResourceRep policy : policies.getFilePolicies()) {
            FilePolicyRestRep policyRestRep = client.fileProtectionPolicies().get(policy.getId());
            if (policyRestRep != null && policyRestRep.getAppliedAt() != null && policyRestRep.getAppliedAt().equalsIgnoreCase("file_system")) {
                fileSystemPolicies.add(policyRestRep);
            }
        }
    }
    return fileSystemPolicies;
}
Also used : ViPRCoreClient(com.emc.vipr.client.ViPRCoreClient) FilePolicyRestRep(com.emc.storageos.model.file.policy.FilePolicyRestRep) ArrayList(java.util.ArrayList) NamedRelatedResourceRep(com.emc.storageos.model.NamedRelatedResourceRep) FilePolicyListRestRep(com.emc.storageos.model.file.policy.FilePolicyListRestRep)

Example 4 with FilePolicyListRestRep

use of com.emc.storageos.model.file.policy.FilePolicyListRestRep in project coprhd-controller by CoprHD.

the class FilePolicyService method getFilePoliciesForGivenUser.

protected FilePolicyListRestRep getFilePoliciesForGivenUser() {
    FilePolicyListRestRep filePolicyList = new FilePolicyListRestRep();
    List<URI> ids = _dbClient.queryByType(FilePolicy.class, true);
    List<FilePolicy> filePolicies = _dbClient.queryObject(FilePolicy.class, ids);
    StorageOSUser user = getUserFromContext();
    // else only return the list, which input tenant has access.
    if (_permissionsHelper.userHasGivenRole(user, null, Role.SYSTEM_ADMIN, Role.SYSTEM_MONITOR)) {
        for (FilePolicy filePolicy : filePolicies) {
            filePolicyList.add(toNamedRelatedResource(filePolicy, filePolicy.getFilePolicyName()));
        }
    } else {
        // otherwise, filter by only authorized to use
        URI tenant = null;
        tenant = URI.create(user.getTenantId());
        Set<FilePolicy> policySet = new HashSet<FilePolicy>();
        for (FilePolicy filePolicy : filePolicies) {
            if (_permissionsHelper.tenantHasUsageACL(tenant, filePolicy)) {
                policySet.add(filePolicy);
            }
        }
        // Also adding vpools which sub-tenants of the user have access to.
        List<URI> subtenants = _permissionsHelper.getSubtenantsWithRoles(user);
        for (FilePolicy filePolicy : filePolicies) {
            if (_permissionsHelper.tenantHasUsageACL(subtenants, filePolicy)) {
                policySet.add(filePolicy);
            }
        }
        for (FilePolicy filePolicy : policySet) {
            filePolicyList.add(toNamedRelatedResource(filePolicy, filePolicy.getFilePolicyName()));
        }
    }
    return filePolicyList;
}
Also used : FilePolicy(com.emc.storageos.db.client.model.FilePolicy) MapFilePolicy(com.emc.storageos.api.mapper.functions.MapFilePolicy) StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) FilePolicyListRestRep(com.emc.storageos.model.file.policy.FilePolicyListRestRep) URI(java.net.URI) HashSet(java.util.HashSet)

Aggregations

FilePolicyListRestRep (com.emc.storageos.model.file.policy.FilePolicyListRestRep)4 NamedRelatedResourceRep (com.emc.storageos.model.NamedRelatedResourceRep)3 MapFilePolicy (com.emc.storageos.api.mapper.functions.MapFilePolicy)1 FilePolicy (com.emc.storageos.db.client.model.FilePolicy)1 FilePolicyRestRep (com.emc.storageos.model.file.policy.FilePolicyRestRep)1 StorageOSUser (com.emc.storageos.security.authentication.StorageOSUser)1 ViPRCoreClient (com.emc.vipr.client.ViPRCoreClient)1 FlashException (controllers.util.FlashException)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 ScheculePoliciesDataTable (models.datatable.ScheculePoliciesDataTable)1 Test (org.junit.Test)1