Search in sources :

Example 76 with DateTimeFormatter

use of org.joda.time.format.DateTimeFormatter in project oxTrust by GluuFederation.

the class Scim2UserService method updateUser.

public User updateUser(String id, User user) throws Exception {
    GluuCustomPerson gluuPerson = personService.getPersonByInum(id);
    if (gluuPerson == null) {
        throw new EntryPersistenceException("Scim2UserService.updateUser(): " + "Resource " + id + " not found");
    } else {
        // Validate if attempting to update userName of a different id
        if (user.getUserName() != null) {
            GluuCustomPerson personToFind = new GluuCustomPerson();
            personToFind.setUid(user.getUserName());
            List<GluuCustomPerson> foundPersons = personService.findPersons(personToFind, 2);
            if (foundPersons != null && foundPersons.size() > 0) {
                for (GluuCustomPerson foundPerson : foundPersons) {
                    if (foundPerson != null && !foundPerson.getInum().equalsIgnoreCase(gluuPerson.getInum())) {
                        throw new DuplicateEntryException("Cannot update userName of a different id: " + user.getUserName());
                    }
                }
            }
        }
    }
    GluuCustomPerson updatedGluuPerson = copyUtils2.copy(user, gluuPerson, true);
    if (user.getGroups().size() > 0) {
        serviceUtil.groupMembersAdder(updatedGluuPerson, personService.getDnForPerson(id));
    }
    log.info(" Setting meta: update user ");
    // Date should be in UTC format
    DateTimeFormatter dateTimeFormatter = ISODateTimeFormat.dateTime().withZoneUTC();
    Date dateLastModified = DateTime.now().toDate();
    updatedGluuPerson.setAttribute("oxTrustMetaLastModified", dateTimeFormatter.print(dateLastModified.getTime()));
    if (updatedGluuPerson.getAttribute("oxTrustMetaLocation") == null || (updatedGluuPerson.getAttribute("oxTrustMetaLocation") != null && updatedGluuPerson.getAttribute("oxTrustMetaLocation").isEmpty())) {
        String relativeLocation = "/scim/v2/Users/" + id;
        updatedGluuPerson.setAttribute("oxTrustMetaLocation", relativeLocation);
    }
    // Sync email, forward ("oxTrustEmail" -> "mail")
    updatedGluuPerson = serviceUtil.syncEmailForward(updatedGluuPerson, true);
    // For custom script: update user
    if (externalScimService.isEnabled()) {
        externalScimService.executeScimUpdateUserMethods(updatedGluuPerson);
    }
    personService.updatePerson(updatedGluuPerson);
    log.debug(" person updated ");
    User updatedUser = copyUtils2.copy(updatedGluuPerson, null);
    return updatedUser;
}
Also used : GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) User(org.gluu.oxtrust.model.scim2.User) ScimPatchUser(org.gluu.oxtrust.model.scim2.ScimPatchUser) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) DuplicateEntryException(org.gluu.site.ldap.exception.DuplicateEntryException) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) Date(java.util.Date)

Example 77 with DateTimeFormatter

use of org.joda.time.format.DateTimeFormatter in project ddf by codice.

the class TestCswFilterDelegate method testDuringAlteredCreatedDateMapping.

@Test
public void testDuringAlteredCreatedDateMapping() throws JAXBException, SAXException, IOException {
    String replacedTemporalProperty = "myCreatedDate";
    CswSourceConfiguration cswSourceConfiguration = initCswSourceConfiguration(CswAxisOrder.LAT_LON, false, CswConstants.CSW_TYPE, effectiveDateMapping, replacedTemporalProperty, modifiedDateMapping, CswConstants.CSW_IDENTIFIER);
    CswFilterDelegate localCswFilterDelegate = createCswFilterDelegate(cswSourceConfiguration);
    String xml = getXmlProperty(localCswFilterDelegate, propertyNameCreated, BETWEEN, testStartDate.toCalendar(null).getTime(), testEndDate.toCalendar(null).getTime());
    DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
    String startDateStr = fmt.print(testStartDate);
    String endDateStr = fmt.print(testEndDate);
    String testResponse = duringXml.replace(REPLACE_START_DATE, startDateStr).replace(REPLACE_END_DATE, endDateStr).replace(REPLACE_TEMPORAL_PROPERTY, replacedTemporalProperty);
    assertXMLEqual(testResponse, xml);
}
Also used : CswSourceConfiguration(org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) Test(org.junit.Test)

Example 78 with DateTimeFormatter

use of org.joda.time.format.DateTimeFormatter in project ddf by codice.

the class TestCswFilterDelegate method testBefore.

@Test
public void testBefore() throws Exception {
    // Setup
    CswSourceConfiguration cswSourceConfiguration = initCswSourceConfiguration(CswAxisOrder.LAT_LON, false, CswConstants.CSW_TYPE, effectiveDateMapping, createdDateMapping, modifiedDateMapping, CswConstants.CSW_IDENTIFIER);
    DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
    String dateStr = fmt.print(testStartDate);
    String controlFilterAsXml = beforeXml.replace(REPLACE_TEMPORAL_PROPERTY, createdDateMapping).replace(REPLACE_DATE, dateStr);
    CswFilterDelegate localCswFilterDelegate = createCswFilterDelegate(cswSourceConfiguration);
    // Perform Test
    FilterType filterType = localCswFilterDelegate.before(propertyNameCreated, testStartDate.toDate());
    // Verify
    assertXMLEqual(controlFilterAsXml, getXmlFromMarshaller(filterType));
}
Also used : CswSourceConfiguration(org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration) FilterType(net.opengis.filter.v_1_1_0.FilterType) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) Test(org.junit.Test)

Example 79 with DateTimeFormatter

use of org.joda.time.format.DateTimeFormatter in project ddf by codice.

the class TestCswFilterDelegate method testDuringAlteredEffectiveDateMapping.

@Test
public void testDuringAlteredEffectiveDateMapping() throws JAXBException, SAXException, IOException {
    String replacedTemporalProperty = "myEffectiveDate";
    CswSourceConfiguration cswSourceConfiguration = initCswSourceConfiguration(CswAxisOrder.LAT_LON, false, CswConstants.CSW_TYPE, replacedTemporalProperty, createdDateMapping, modifiedDateMapping, CswConstants.CSW_IDENTIFIER);
    CswFilterDelegate localCswFilterDelegate = createCswFilterDelegate(cswSourceConfiguration);
    String xml = getXmlProperty(localCswFilterDelegate, propertyNameEffective, BETWEEN, testStartDate.toCalendar(null).getTime(), testEndDate.toCalendar(null).getTime());
    DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
    String startDateStr = fmt.print(testStartDate);
    String endDateStr = fmt.print(testEndDate);
    String testResponse = duringXml.replace(REPLACE_START_DATE, startDateStr).replace(REPLACE_END_DATE, endDateStr).replace(REPLACE_TEMPORAL_PROPERTY, replacedTemporalProperty);
    assertXMLEqual(testResponse, xml);
}
Also used : CswSourceConfiguration(org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) Test(org.junit.Test)

Example 80 with DateTimeFormatter

use of org.joda.time.format.DateTimeFormatter in project ddf by codice.

the class TestCswSource method testAbsoluteTemporalSearchPropertyIsBetweenQuery.

@Test
public void testAbsoluteTemporalSearchPropertyIsBetweenQuery() throws JAXBException, UnsupportedQueryException, DatatypeConfigurationException, SAXException, IOException, SecurityServiceException {
    // Setup
    String expectedXml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\r\n" + "<GetRecords resultType=\"results\" outputFormat=\"application/xml\" " + "    outputSchema=\"http://www.opengis.net/cat/csw/2.0.2\" startPosition=\"1\" " + "    maxRecords=\"10\" service=\"CSW\" version=\"2.0.2\" " + "    xmlns=\"http://www.opengis.net/cat/csw/2.0.2\" " + "    xmlns:csw=\"http://www.opengis.net/cat/csw/2.0.2\" " + "    xmlns:ogc=\"http://www.opengis.net/ogc\">\n " + "    <Query typeNames=\"csw:Record\">\r\n" + "        <ElementSetName>full</ElementSetName>\r\n" + "        <Constraint version=\"1.1.0\">\r\n" + "            <ogc:Filter>\r\n" + "                <ogc:PropertyIsBetween>\r\n" + "                    <ogc:PropertyName>effective</ogc:PropertyName>\r\n" + "                    <ogc:LowerBoundary>\r\n" + "                        <ogc:Literal>START_DATE_TIME</ogc:Literal>\r\n" + "                    </ogc:LowerBoundary>\r\n" + "                    <ogc:UpperBoundary>\r\n" + "                        <ogc:Literal>END_DATE_TIME</ogc:Literal>\r\n" + "                    </ogc:UpperBoundary>\r\n" + "                </ogc:PropertyIsBetween>\r\n" + "            </ogc:Filter>\r\n" + "        </Constraint>\r\n" + "    </Query>\r\n" + "</GetRecords>";
    final int pageSize = 10;
    final int numRecordsReturned = 1;
    final long numRecordsMatched = 10;
    setupMockContextForMetacardTypeRegistrationAndUnregistration(getDefaultContentTypes());
    try {
        configureMockCsw(numRecordsReturned, numRecordsMatched, CswConstants.VERSION_2_0_2);
    } catch (CswException e) {
        fail("Could not configure Mock Remote CSW: " + e.getMessage());
    }
    // Create start and end date times that are before current time
    DateTime startDate = new DateTime(2013, 5, 1, 0, 0, 0, 0);
    DateTime endDate = new DateTime(2013, 12, 31, 0, 0, 0, 0);
    DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
    // Load the expected start and end date time into the excepted result
    // XML
    expectedXml = expectedXml.replace("START_DATE_TIME", fmt.print(startDate));
    expectedXml = expectedXml.replace("END_DATE_TIME", fmt.print(endDate));
    // Single absolute time range to search across
    Filter temporalFilter = builder.attribute(Metacard.EFFECTIVE).is().during().dates(startDate.toDate(), endDate.toDate());
    QueryImpl temporalQuery = new QueryImpl(temporalFilter);
    temporalQuery.setPageSize(pageSize);
    AbstractCswSource cswSource = getCswSource(mockCsw, mockContext);
    cswSource.setCswUrl(URL);
    cswSource.setId(ID);
    // Perform test
    cswSource.query(new QueryRequestImpl(temporalQuery));
    // Verify
    ArgumentCaptor<GetRecordsType> captor = ArgumentCaptor.forClass(GetRecordsType.class);
    try {
        verify(mockCsw, atLeastOnce()).getRecords(captor.capture());
    } catch (CswException e) {
        fail("Could not verify Mock CSW record count " + e.getMessage());
    }
    GetRecordsType getRecordsType = captor.getValue();
    String xml = getGetRecordsTypeAsXml(getRecordsType);
    Diff xmlDiff = new Diff(expectedXml, xml);
    if (!xmlDiff.similar()) {
        LOGGER.error("Unexpected XML request sent");
        LOGGER.error("Expected: {}", expectedXml);
        LOGGER.error("Actual: {}", xml);
    }
    assertXMLEqual(expectedXml, xml);
}
Also used : Diff(org.custommonkey.xmlunit.Diff) CswException(org.codice.ddf.spatial.ogc.csw.catalog.common.CswException) GetRecordsType(net.opengis.cat.csw.v_2_0_2.GetRecordsType) Matchers.anyString(org.mockito.Matchers.anyString) DateTime(org.joda.time.DateTime) QueryImpl(ddf.catalog.operation.impl.QueryImpl) Filter(org.opengis.filter.Filter) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) Test(org.junit.Test)

Aggregations

DateTimeFormatter (org.joda.time.format.DateTimeFormatter)209 DateTime (org.joda.time.DateTime)95 Date (java.util.Date)40 Test (org.junit.Test)25 DateTimeZone (org.joda.time.DateTimeZone)19 ArrayList (java.util.ArrayList)16 HashMap (java.util.HashMap)16 SolrInputDocument (org.apache.solr.common.SolrInputDocument)12 IndexSchema (org.apache.solr.schema.IndexSchema)12 DateTimeFormatterBuilder (org.joda.time.format.DateTimeFormatterBuilder)12 CswSourceConfiguration (org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration)10 IOException (java.io.IOException)9 Calendar (java.util.Calendar)8 Map (java.util.Map)8 DatasetConfigDTO (com.linkedin.thirdeye.datalayer.dto.DatasetConfigDTO)7 FormatDateTimeFormatter (org.elasticsearch.common.joda.FormatDateTimeFormatter)7 Test (org.testng.annotations.Test)7 TimeSpec (com.linkedin.thirdeye.api.TimeSpec)6 FilterType (net.opengis.filter.v_1_1_0.FilterType)6 Deployment (org.activiti.engine.test.Deployment)6