Search in sources :

Example 1 with SourceName

use of com.google.cloud.securitycenter.v1.SourceName in project ORCID-Source by ORCID.

the class ActivityValidatorTest method validateDuplicatedExtIds_duplicatesFoundTest.

@SuppressWarnings("deprecation")
@Test(expected = OrcidDuplicatedActivityException.class)
public void validateDuplicatedExtIds_duplicatesFoundTest() {
    SourceEntity source1 = mock(SourceEntity.class);
    when(source1.getSourceName()).thenReturn("source name");
    when(source1.getSourceId()).thenReturn("APP-00000000000000");
    SourceClientId sourceClientId = new SourceClientId();
    sourceClientId.setPath("APP-00000000000000");
    Source source2 = mock(Source.class);
    when(source2.getSourceName()).thenReturn(new SourceName("source name"));
    when(source2.getSourceClientId()).thenReturn(sourceClientId);
    ExternalIDs extIds1 = getExternalIDs();
    ExternalIDs extIds2 = getExternalIDs();
    activityValidator.checkExternalIdentifiersForDuplicates(extIds1, extIds2, source2, source1);
}
Also used : ExternalIDs(org.orcid.jaxb.model.record_v2.ExternalIDs) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) SourceClientId(org.orcid.jaxb.model.common_v2.SourceClientId) SourceName(org.orcid.jaxb.model.common_v2.SourceName) Source(org.orcid.jaxb.model.common_v2.Source) Test(org.junit.Test)

Example 2 with SourceName

use of com.google.cloud.securitycenter.v1.SourceName in project ORCID-Source by ORCID.

the class ActivityValidatorTest method validateDuplicatedExtIds_noDuplicatesTest.

/**
 * VALIDATE DUPLICATED EXTERNAL IDENTIFIERS
 */
@SuppressWarnings("deprecation")
@Test
public void validateDuplicatedExtIds_noDuplicatesTest() {
    SourceEntity source1 = mock(SourceEntity.class);
    when(source1.getSourceName()).thenReturn("source name");
    when(source1.getSourceId()).thenReturn("APP-00000000000000");
    SourceOrcid sourceOrcid = new SourceOrcid();
    sourceOrcid.setPath("0000-0000-0000-0000");
    Source source2 = mock(Source.class);
    when(source2.getSourceName()).thenReturn(new SourceName("other source name"));
    when(source2.getSourceOrcid()).thenReturn(sourceOrcid);
    ExternalIDs extIds1 = getExternalIDs();
    ExternalIDs extIds2 = getExternalIDs();
    activityValidator.checkExternalIdentifiersForDuplicates(extIds1, extIds2, source2, source1);
}
Also used : ExternalIDs(org.orcid.jaxb.model.record_v2.ExternalIDs) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) SourceName(org.orcid.jaxb.model.common_v2.SourceName) SourceOrcid(org.orcid.jaxb.model.common_v2.SourceOrcid) Source(org.orcid.jaxb.model.common_v2.Source) Test(org.junit.Test)

Example 3 with SourceName

use of com.google.cloud.securitycenter.v1.SourceName in project ORCID-Source by ORCID.

the class EmailMessageSenderTest method testCreateDigest.

@Test
public void testCreateDigest() throws IOException {
    OrcidProfile orcidProfile = new OrcidProfile();
    orcidProfile.setOrcidIdentifier(new OrcidIdentifier("0000-0000-0000-0000"));
    OrcidBio orcidBio = new OrcidBio();
    orcidProfile.setOrcidBio(orcidBio);
    PersonalDetails personalDetails = new PersonalDetails();
    orcidBio.setPersonalDetails(personalDetails);
    personalDetails.setGivenNames(new GivenNames("John"));
    personalDetails.setFamilyName(new FamilyName("Watson"));
    OrcidInternal orcidInternal = new OrcidInternal();
    Preferences preferences = new Preferences();
    orcidProfile.setOrcidInternal(orcidInternal);
    orcidInternal.setPreferences(preferences);
    preferences.setSendEmailFrequencyDays("7.0");
    List<Notification> notifications = new ArrayList<>();
    NotificationPermission notification1 = new NotificationPermission();
    notification1.setPutCode(1L);
    Items activities1 = new Items();
    notification1.setItems(activities1);
    activities1.getItems().add(createActivity(ItemType.WORK, "Work 1", "123446/67654"));
    activities1.getItems().add(createActivity(ItemType.WORK, "Work 2", "http://dx.doi.org/123446/67655"));
    notification1.setCreatedDate(DateUtils.convertToXMLGregorianCalendar("2014-07-10T13:39:31"));
    notification1.setAuthorizationUrl(new AuthorizationUrl("https://thirdparty.com/add-to-orcid/12345"));
    Source source1 = new Source();
    source1.setSourceName(new SourceName("Super Institution 1"));
    source1.setSourceClientId(new SourceClientId("APP-5555-5555-5555-5555"));
    notification1.setSource(source1);
    notifications.add(notification1);
    NotificationPermission notification2 = new NotificationPermission();
    notification2.setPutCode(2L);
    Items activities2 = new Items();
    notification2.setItems(activities2);
    activities2.getItems().add(createActivity(ItemType.EMPLOYMENT, "Employment 1 ", "12345/abc"));
    notification2.setCreatedDate(DateUtils.convertToXMLGregorianCalendar("2014-08-17T10:22:15"));
    notification2.setAuthorizationUrl(new AuthorizationUrl("https://thirdparty.com/add-to-orcid/abc"));
    Source source2 = new Source();
    source2.setSourceName(new SourceName("Super Institution 1"));
    source2.setSourceClientId(new SourceClientId("APP-5555-5555-5555-5555"));
    notification2.setSource(source2);
    notifications.add(notification2);
    NotificationPermission notification3 = new NotificationPermission();
    notification3.setPutCode(3L);
    Items activities3 = new Items();
    notification3.setItems(activities3);
    activities3.getItems().add(createActivity(ItemType.WORK, "Work 3", "12345/def"));
    activities3.getItems().add(createActivity(ItemType.WORK, "Work 4", "12345/ghi"));
    notification3.setCreatedDate(DateUtils.convertToXMLGregorianCalendar("2014-07-10T08:53:56"));
    notification3.setAuthorizationUrl(new AuthorizationUrl("https://thirdparty.com/add-to-orcid/def"));
    Source source3 = new Source();
    source3.setSourceName(new SourceName("Lovely Publisher 1"));
    notification3.setSource(source3);
    source3.setSourceClientId(new SourceClientId("APP-ABCD-ABCD-ABCD-ABCD"));
    notifications.add(notification3);
    NotificationCustom notification4 = new NotificationCustom();
    notification4.setPutCode(4L);
    notification4.setSubject("We have release a new messaging feature");
    notification4.setCreatedDate(DateUtils.convertToXMLGregorianCalendar("2014-07-10T08:53:56"));
    notifications.add(notification4);
    NotificationCustom notification5 = new NotificationCustom();
    notification5.setPutCode(5L);
    notification5.setSubject("The ORCID registry is now available in Orc");
    notification5.setCreatedDate(DateUtils.convertToXMLGregorianCalendar("2014-07-11T06:42:18"));
    notifications.add(notification5);
    NotificationAmended notification6 = new NotificationAmended();
    notification6.setPutCode(6L);
    notification6.setSubject("Amended by member");
    notification6.setAmendedSection(AmendedSection.FUNDING);
    notification6.setCreatedDate(DateUtils.convertToXMLGregorianCalendar("2014-07-12T18:44:36"));
    notification6.setSource(source3);
    notifications.add(notification6);
    EmailMessage emailMessage = emailMessageSender.createDigest("0000-0000-0000-0000", notifications);
    assertNotNull(emailMessage);
    String expectedBodyText = IOUtils.toString(getClass().getResourceAsStream("example_digest_email_body.txt"));
    String expectedBodyHtml = IOUtils.toString(getClass().getResourceAsStream("example_digest_email_body.html"));
    assertTrue(expectedBodyText.contains("Lovely Publisher 1 has updated recent funding on your ORCID record."));
    assertTrue(expectedBodyHtml.contains("Lovely Publisher 1 has updated recent funding on your ORCID record."));
    assertTrue(expectedBodyText.contains("Super Institution 1: Request to add items"));
    assertTrue(expectedBodyHtml.contains("Super Institution 1: Request to add items"));
    assertTrue(expectedBodyText.contains("/action"));
    assertTrue(expectedBodyHtml.contains("/action"));
    assertEquals("[ORCID] John Watson you have 6 new notifications", emailMessage.getSubject());
}
Also used : OrcidBio(org.orcid.jaxb.model.message.OrcidBio) FamilyName(org.orcid.jaxb.model.message.FamilyName) SourceClientId(org.orcid.jaxb.model.common_v2.SourceClientId) OrcidInternal(org.orcid.jaxb.model.message.OrcidInternal) ArrayList(java.util.ArrayList) SourceName(org.orcid.jaxb.model.common_v2.SourceName) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) PersonalDetails(org.orcid.jaxb.model.message.PersonalDetails) Notification(org.orcid.jaxb.model.notification_v2.Notification) Source(org.orcid.jaxb.model.common_v2.Source) OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) AuthorizationUrl(org.orcid.jaxb.model.notification.permission_v2.AuthorizationUrl) NotificationCustom(org.orcid.jaxb.model.notification.custom_v2.NotificationCustom) OrcidIdentifier(org.orcid.jaxb.model.message.OrcidIdentifier) GivenNames(org.orcid.jaxb.model.message.GivenNames) NotificationPermission(org.orcid.jaxb.model.notification.permission_v2.NotificationPermission) Items(org.orcid.jaxb.model.notification.permission_v2.Items) Preferences(org.orcid.jaxb.model.message.Preferences) NotificationAmended(org.orcid.jaxb.model.notification.amended_v2.NotificationAmended) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 4 with SourceName

use of com.google.cloud.securitycenter.v1.SourceName in project google-cloud-java by GoogleCloudPlatform.

the class FindingSnippets method groupActiveFindingsWithSourceAndCompareDuration.

// [END securitycenter_group_active_findings_with_source_at_time]
/**
 * Group active findings under an organization and a source by their state_changes
 * (ADDED/CHANGED/UNCHANGED) during a period.
 *
 * @param sourceName The source to limit the findings to.
 */
// [START securitycenter_group_active_findings_with_source_and_compare_duration]
static ImmutableList<GroupResult> groupActiveFindingsWithSourceAndCompareDuration(SourceName sourceName, Duration duration) {
    try (SecurityCenterClient client = SecurityCenterClient.create()) {
        // SourceName sourceName = SourceName.of(/*organization=*/"123234324",/*source=*/
        // "423432321");
        GroupFindingsRequest.Builder request = GroupFindingsRequest.newBuilder().setParent(sourceName.toString()).setGroupBy("state_change").setFilter("state=\"ACTIVE\"");
        request.getCompareDurationBuilder().setSeconds(duration.getSeconds()).setNanos(duration.getNano());
        // Call the API.
        GroupFindingsPagedResponse response = client.groupFindings(request.build());
        // This creates one list for all findings.  If your organization has a large number of
        // findings
        // this can cause out of memory issues.  You can process them batches by returning
        // the Iterable returned response.iterateAll() directly.
        ImmutableList<GroupResult> results = ImmutableList.copyOf(response.iterateAll());
        System.out.println("Findings:");
        System.out.println(results);
        return results;
    } catch (IOException e) {
        throw new RuntimeException("Couldn't create client.", e);
    }
}
Also used : GroupFindingsRequest(com.google.cloud.securitycenter.v1.GroupFindingsRequest) GroupResult(com.google.cloud.securitycenter.v1.GroupResult) GroupFindingsPagedResponse(com.google.cloud.securitycenter.v1.SecurityCenterClient.GroupFindingsPagedResponse) IOException(java.io.IOException) SecurityCenterClient(com.google.cloud.securitycenter.v1.SecurityCenterClient)

Example 5 with SourceName

use of com.google.cloud.securitycenter.v1.SourceName in project google-cloud-java by GoogleCloudPlatform.

the class FindingSnippets method testIamPermissions.

// [END securitycenter_list_findings_at_time]
/**
 * Demonstrate calling testIamPermissions to determin if the service account has the correct
 * permissions.
 *
 * @param sourceName The source to create a finding for.
 */
// [START securitycenter_test_iam]
static TestIamPermissionsResponse testIamPermissions(SourceName sourceName) {
    try (SecurityCenterClient client = SecurityCenterClient.create()) {
        // SourceName sourceName = SourceName.of(/*organizationId=*/"123234324",
        // /*sourceId=*/"423432321");
        // Iam permission to test.
        List<String> permissionsToTest = new ArrayList<>();
        permissionsToTest.add("securitycenter.findings.update");
        // Call the API.
        TestIamPermissionsResponse response = client.testIamPermissions(sourceName.toString(), permissionsToTest);
        System.out.println("IAM Permission:");
        System.out.println(response);
        return response;
    } catch (IOException e) {
        throw new RuntimeException("Couldn't create client.", e);
    }
}
Also used : TestIamPermissionsResponse(com.google.iam.v1.TestIamPermissionsResponse) ArrayList(java.util.ArrayList) IOException(java.io.IOException) SecurityCenterClient(com.google.cloud.securitycenter.v1.SecurityCenterClient)

Aggregations

SecurityCenterClient (com.google.cloud.securitycenter.v1.SecurityCenterClient)16 IOException (java.io.IOException)16 GroupFindingsRequest (com.google.cloud.securitycenter.v1.GroupFindingsRequest)5 GroupResult (com.google.cloud.securitycenter.v1.GroupResult)5 GroupFindingsPagedResponse (com.google.cloud.securitycenter.v1.SecurityCenterClient.GroupFindingsPagedResponse)5 ListFindingsRequest (com.google.cloud.securitycenter.v1.ListFindingsRequest)4 ListFindingsResult (com.google.cloud.securitycenter.v1.ListFindingsResponse.ListFindingsResult)4 ListFindingsPagedResponse (com.google.cloud.securitycenter.v1.SecurityCenterClient.ListFindingsPagedResponse)4 SourceName (org.orcid.jaxb.model.common_v2.SourceName)4 Test (org.junit.Test)3 Source (org.orcid.jaxb.model.common_v2.Source)3 Instant (org.threeten.bp.Instant)3 Finding (com.google.cloud.securitycenter.v1.Finding)2 Source (com.google.cloud.securitycenter.v1.Source)2 SourceName (com.google.cloud.securitycenter.v1.SourceName)2 Policy (com.google.iam.v1.Policy)2 ArrayList (java.util.ArrayList)2 SourceClientId (org.orcid.jaxb.model.common_v2.SourceClientId)2 ExternalIDs (org.orcid.jaxb.model.record_v2.ExternalIDs)2 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)2