public static function isValid(&$properties_dictionary, $limit_to_keys, &$error) { // Check each property is valid // if (isset($properties_dictionary[UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION])) { $properties = array('rawIdentifier' => $properties_dictionary[UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION]); if (ValidationC::should_test_property(UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION, $properties_dictionary, true, $limit_to_keys) && !UniversallyUniqueIdentifier::isValid($properties, true, $error)) { // Identifier was not valid // return false; } } if (ValidationC::should_test_property(UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_CREATED, $properties_dictionary, true, $limit_to_keys) && !UniversallyUniqueObject::propertyIsValid(UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_CREATED, $properties_dictionary[UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_CREATED], $error)) { // Date created was not valid // return false; } if (ValidationC::should_test_property(UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_UPDATED, $properties_dictionary, true, $limit_to_keys) && !UniversallyUniqueObject::propertyIsValid(UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_UPDATED, $properties_dictionary[UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_UPDATED], $error)) { // Date updated was not valid // return false; } if (ValidationC::should_test_property(UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_CREATED, $properties_dictionary, true, $limit_to_keys) && ValidationC::should_test_property(UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_UPDATED, $properties_dictionary, true, $limit_to_keys)) { // Date updated cannot be before date created // if ($properties_dictionary[UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_CREATED] > $properties_dictionary[UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_UPDATED]) { // Updated was before created // $error = Error::withDomain(VALIDATION_ERROR_DOMAIN, VALIDATION_ERROR_CODE_INVALID_PROPERTY, UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_CREATED . ' was before ' . UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_UPDATED); return false; } } return true; }
public static function propertyIsValid($property_name, &$property_value, &$error) { if (!parent::propertyIsValid($property_name, $property_value, $error)) { return false; } if ($property_name === USER_KEY_NOTIFICATION_DEVICE_IDENTIFIERS) { // Check the data is an array of strings // if (!is_array($property_value)) { // Unrecognised property name // $error = Error::withDomain(VALIDATION_ERROR_DOMAIN, VALIDATION_ERROR_CODE_INVALID_PROPERTY, 'Notification device identifiers must be an array'); return false; } // Check each element is a string // foreach ($property_value as $item) { if (!is_string($item)) { // Throw error, each notificationDeviceIdentifiers must be a string // $error = Error::withDomain(VALIDATION_ERROR_DOMAIN, VALIDATION_ERROR_CODE_INVALID_PROPERTY, 'Each notification device identifier must be a string.'); return false; } } } return true; }
public static function isValid(&$properties_dictionary, $limit_to_keys, &$error) { // Check each property is valid // if (!parent::isValid($properties_dictionary, $limit_to_keys, $error)) { return false; } // First name, surname, name // if (ValidationC::should_test_property(CREATINGUSER_KEY_FIRST_NAME, $properties_dictionary, true, $limit_to_keys) && !CreatingUser::propertyIsValid(CREATINGUSER_KEY_FIRST_NAME, $properties_dictionary[CREATINGUSER_KEY_FIRST_NAME], $error)) { return false; } if (ValidationC::should_test_property(CREATINGUSER_KEY_SURNAME, $properties_dictionary, true, $limit_to_keys) && !CreatingUser::propertyIsValid(CREATINGUSER_KEY_SURNAME, $properties_dictionary[CREATINGUSER_KEY_SURNAME], $error)) { return false; } if (ValidationC::should_test_property(CREATINGUSER_KEY_NAME, $properties_dictionary, true, $limit_to_keys) && !CreatingUser::propertyIsValid(CREATINGUSER_KEY_NAME, $properties_dictionary[CREATINGUSER_KEY_NAME], $error)) { return false; } if (ValidationC::should_test_property(CREATINGUSER_KEY_GENDER, $properties_dictionary, true, $limit_to_keys) && !CreatingUser::propertyIsValid(CREATINGUSER_KEY_GENDER, $properties_dictionary[CREATINGUSER_KEY_GENDER], $error)) { return false; } $should_test_all_names = ValidationC::should_test_property(CREATINGUSER_KEY_FIRST_NAME, $properties_dictionary, true, $limit_to_keys) && ValidationC::should_test_property(CREATINGUSER_KEY_SURNAME, $properties_dictionary, true, $limit_to_keys) && ValidationC::should_test_property(CREATINGUSER_KEY_NAME, $properties_dictionary, true, $limit_to_keys); if ($should_test_all_names && (empty($properties_dictionary[CREATINGUSER_KEY_FIRST_NAME]) || isset($properties_dictionary[CREATINGUSER_KEY_SURNAME])) && isset($properties_dictionary[CREATINGUSER_KEY_NAME])) { // Set either first name and surname, or, just a name // $error = Error::withDomain(VALIDATION_ERROR_DOMAIN, VALIDATION_ERROR_CODE_INVALID_PROPERTY, 'When setting a name, set either ' . CREATINGUSER_KEY_FIRST_NAME . ' and ' . CREATINGUSER_KEY_SURNAME . ', or, just a ' . CREATINGUSER_KEY_NAME . '.'); return false; } return true; }
public static function show(Inputter $inputter, JSONOutputter $outputter) { // Show // $id = $inputter->additional_uri_arguments[0]; $error = null; UniversallyUniqueIdentifier::propertyIsValid('rawIdentifier', $id, $error); if (isset($error)) { $outputter->print_error($error); } // User ID // $client = new Everyman\Neo4j\Client('events.sb04.stations.graphenedb.com', 24789); $client->getTransport()->setAuth('Events', '3TP9LHROhv8LIcGmbYzq'); $query_string = 'MATCH (object:Album) WHERE object.' . UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION . ' = \'' . $id . '\' RETURN object'; $query = new Everyman\Neo4j\Cypher\Query($client, $query_string); $result = $query->getResultSet(); if (count($result) > 0) { // Compare sent data is equal to data retrieved // $object = $result[0]['object']; // Print data // $outputter->print_data(array(Album::printer_dictionary($object))); } else { // Throw error, user doesn't exists // $error = Error::withDomain(PRIVATE_EVENTS_REST_CONTROLLER_ERROR_DOMAIN, PRIVATE_EVENTS_REST_CONTROLLER_ERROR_CODE_ENTITY_DOES_NOT_EXIST, 'Album with ID does not exist.'); $outputter->print_error($error); } }
public static function isValid(&$properties_dictionary, $limit_to_keys, &$error) { // Check each property is valid // if (!parent::isValid($properties_dictionary, $limit_to_keys, $error)) { return false; } if (ValidationC::should_test_property(CONFINED_DATE_START, $properties_dictionary, true, $limit_to_keys) && !ConfinedDate::propertyIsValid(CONFINED_DATE_START, $properties_dictionary[CONFINED_DATE_START], $error)) { // Start date was not valid // return false; } if (ValidationC::should_test_property(CONFINED_DATE_END, $properties_dictionary, true, $limit_to_keys) && !ConfinedDate::propertyIsValid(CONFINED_DATE_END, $properties_dictionary[CONFINED_DATE_END], $error)) { // End date was not valid // return false; } if (ValidationC::should_test_property(CONFINED_DATE_START, $properties_dictionary, true, $limit_to_keys) && ValidationC::should_test_property(CONFINED_DATE_END, $properties_dictionary, true, $limit_to_keys)) { // Start is before end // if ($properties_dictionary[CONFINED_DATE_START] > $properties_dictionary[CONFINED_DATE_END]) { $error = Error::withDomain(VALIDATION_ERROR_DOMAIN, VALIDATION_ERROR_CODE_INVALID_PROPERTY, 'Start date must be before end.'); return false; } } return true; }
public static function propertyIsValid($property_name, &$property_value, &$error) { if (!parent::propertyIsValid($property_name, $property_value, $error)) { return false; } if ($property_name === LOCATION_KEY_COORDINATE_LATITUDE) { // Should be a number // $property_value = floatval($property_value); if (!is_numeric($property_value)) { // Unrecognised property name // $error = Error::withDomain(VALIDATION_ERROR_DOMAIN, VALIDATION_ERROR_CODE_INVALID_PROPERTY, $property_name . ' should be a number.'); return false; } // Between -90 and 90 // if ($property_value < -90 || $property_value > 90) { // Unrecognised property name // $error = Error::withDomain(VALIDATION_ERROR_DOMAIN, VALIDATION_ERROR_CODE_INVALID_PROPERTY, $property_name . ' should be between -90 and 90.'); return false; } } if ($property_name === LOCATION_KEY_COORDINATE_LONGITUDE) { // Should be a number // $property_value = floatval($property_value); if (!is_numeric($property_value)) { // Unrecognised property name // $error = Error::withDomain(VALIDATION_ERROR_DOMAIN, VALIDATION_ERROR_CODE_INVALID_PROPERTY, $property_name . ' should be a number.'); return false; } // Between -180 and 180 // if ($property_value < -180 || $property_value > 180) { // Unrecognised property name // $error = Error::withDomain(VALIDATION_ERROR_DOMAIN, VALIDATION_ERROR_CODE_INVALID_PROPERTY, $property_name . ' should be between -180 and 180.'); return false; } } if ($property_name === LOCATION_KEY_NAME) { // Should be a string // if (!isset($property_value) || !is_string($property_value)) { // Unrecognised property name // $error = Error::withDomain(VALIDATION_ERROR_DOMAIN, VALIDATION_ERROR_CODE_INVALID_PROPERTY, $property_name . ' should be a string.'); return false; } } return true; }
public static function search_list(Inputter $inputter, JSONOutputter $outputter) { // Search string // $search_string = $inputter->additional_uri_arguments[0]; $user_error = null; if (!is_string($search_string)) { // Throw error, search string is not a string // $error = Error::withDomain(PRIVATE_EVENTS_REST_CONTROLLER_ERROR_DOMAIN, PRIVATE_EVENTS_REST_CONTROLLER_ERROR_CODE_INPUT_UNCONFORMING, 'Search string is not a string.'); $outputter->print_error($error); } // Query // $client = new Everyman\Neo4j\Client('events.sb04.stations.graphenedb.com', 24789); $client->getTransport()->setAuth('Events', '3TP9LHROhv8LIcGmbYzq'); // Users // $query_string_search_users = 'MATCH (foundUser:CreatingUser) ' . 'WHERE (foundUser.' . CREATINGUSER_KEY_FIRST_NAME . ' + " " + foundUser.' . CREATINGUSER_KEY_SURNAME . ') =~ "(?i)' . $search_string . '.*" OR foundUser.' . CREATINGUSER_KEY_NAME . ' =~ "(?i)' . $search_string . '.*" OR foundUser.' . USER_KEY_EMAIL . ' =~ "(?i)' . $search_string . '" ' . 'RETURN foundUser'; $query_search_users = new Everyman\Neo4j\Cypher\Query($client, $query_string_search_users); $result_search_users = $query_search_users->getResultSet(); // Events in scope // $query_string_search_events = 'MATCH (foundCreator:CreatingUser)-[:creator]-(foundEvent:Event)-[:type]-(foundEventType:EventType), (foundOccurrence:EventSpaceTimeOccurrence)-[:occurrence]-(foundEvent) ' . 'WHERE foundEvent.privacy = 1 AND ANY(label IN labels(foundEventType) WHERE label =~ "(?i).*' . $search_string . '.*") ' . 'RETURN foundEvent, foundEventType, foundCreator, collect(foundOccurrence) as foundEventOccurrences'; $query_search_events = new Everyman\Neo4j\Cypher\Query($client, $query_string_search_events); $result_search_events = $query_search_events->getResultSet(); // Output // // Users // $print_users = array(); foreach ($result_search_users as $row) { array_push($print_users, AttendingUser::printer_dictionary($row['foundUser'])); } // Events in scope // $print_events = array(); foreach ($result_search_events as $row) { $event_dictionary = array(); if ($event_dictionary != Event::printer_dictionary($row['foundEvent'])) { $event_dictionary = Event::printer_dictionary($row['foundEvent']); $event_dictionary[EVENT_RELATIONSHIP_NAME_TYPE] = EventType::printer_dictionary($row['foundEventType']); $event_dictionary[EVENT_RELATIONSHIP_NAME_OCCURRENCE] = array(); } foreach ($row['foundEventOccurrences'] as $occurrence) { array_push($event_dictionary[EVENT_RELATIONSHIP_NAME_OCCURRENCE], EventSpaceTimeOccurrence::printer_dictionary($occurrence)); } if ($event_dictionary != Event::printer_dictionary($row['foundEvent'])) { array_push($print_events, $event_dictionary); } } // Print data // $outputter->print_data(array(array("users" => $print_users, "events" => $print_events))); }
function customErrorHandler($errorNumber, $errorString, $errorFile, $errorLineNumber) { // Output all PHP errors as an error in our REST Controller format, this stops any internal errors from // affecting the output of JSON only data (so long as we always check there's no error before processing // a response) // $json_outputter = new JSONOutputter(); $json_outputter->print_error(Error::withDomain('server.internal', $errorNumber, $errorString . ' in ' . $errorFile . ' on line ' . $errorLineNumber)); // Don't execute PHP internal error handler // return true; }
public static function propertyIsValid($property_name, &$property_value, &$error) { if (!parent::propertyIsValid($property_name, $property_value, $error)) { return false; } if (!isset($property_value)) { // Not set // $error = Error::withDomain(VALIDATION_ERROR_DOMAIN, VALIDATION_ERROR_CODE_PROPERTY_NOT_SET, "Invalid property value for '" . $property_name . "'"); return false; } return true; }
public static function propertyIsValid($property_name, &$property_value, &$error) { if (!parent::propertyIsValid($property_name, $property_value, $error)) { return false; } if ($property_name === EVENT_TYPE_PARTY_LAUNCH_KEY_LAUNCH_ITEM_TITLE) { // Item title is a string // if (!isset($property_value) || !is_string($property_value)) { $error = Error::withDomain(VALIDATION_ERROR_DOMAIN, VALIDATION_ERROR_CODE_INVALID_PROPERTY, $property_name . " should be a valid string."); return false; } } return true; }
public static function propertyIsValid($property_name, &$property_value, &$error) { if (!parent::propertyIsValid($property_name, $property_value, $error)) { return false; } if ($property_name === EVENT_TYPE_ANNIVERSARY_KEY_YEAR) { // Year isn't valid // if (is_numeric($property_value) && is_int($property_value)) { $error = Error::withDomain(VALIDATION_ERROR_DOMAIN, VALIDATION_ERROR_CODE_INVALID_PROPERTY, $property_name . " should be a valid year."); return false; } } return true; }
public static function propertyIsValid($property_name, &$property_value, &$error) { if (!parent::propertyIsValid($property_name, $property_value, $error)) { return false; } if ($property_name === MULTIDIMENSIONED_IMAGE_KEY_URL_ICON || $property_name === MULTIDIMENSIONED_IMAGE_KEY_URL_SMALL || $property_name === MULTIDIMENSIONED_IMAGE_KEY_URL_MEDIUM || $property_name === MULTIDIMENSIONED_IMAGE_KEY_URL_LARGE || $property_name === MULTIDIMENSIONED_IMAGE_KEY_URL_ORIGINAL) { // Valid URL // if (!filter_var($property_value, FILTER_VALIDATE_URL)) { // Unrecognised property name // $error = Error::withDomain(VALIDATION_ERROR_DOMAIN, VALIDATION_ERROR_CODE_INVALID_PROPERTY, $property_name . ' should be a valid URL.'); return false; } } return true; }
public static function propertyIsValid($property_name, &$property_value, &$error) { if (!parent::propertyIsValid($property_name, $property_value, $error)) { return false; } if ($property_name === RANGE_POSITION || $property_name === RANGE_LENGTH) { // Position // $property_value = intval($property_value); if (!is_numeric($property_value)) { // Is a number // $error = Error::withDomain(VALIDATION_ERROR_DOMAIN, VALIDATION_ERROR_CODE_INVALID_PROPERTY, $property_name . ' should be a number.'); return false; } } return true; }
public static function propertyIsValid($property_name, &$property_value, &$error) { if (!parent::propertyIsValid($property_name, $property_value, $error)) { return false; } if ($property_name === EVENT_KEY_DRESS_CODE) { // Check the dress code is between first and last dress code value // if (!is_array($property_value)) { // Not array // $error = Error::withDomain(VALIDATION_ERROR_DOMAIN, VALIDATION_ERROR_CODE_INVALID_PROPERTY, $property_name . ' should be an array.'); return false; } else { // Is array // foreach ($property_value as &$value) { $value = intval($value); if (!is_numeric($value)) { // Not unsigned int // $error = Error::withDomain(VALIDATION_ERROR_DOMAIN, VALIDATION_ERROR_CODE_INVALID_PROPERTY, $property_name . ' should be unsigned integers.'); return false; } if ($value < EVENT_VALUE_DRESS_CODE_ANY || $value > EVENT_VALUE_DRESS_CODE_BLACKTIE) { // Dress code is out of bounds // $error = Error::withDomain(VALIDATION_ERROR_DOMAIN, VALIDATION_ERROR_CODE_INVALID_PROPERTY, $property_name . ' is out of bounds.'); return false; } } } } if ($property_name === EVENT_KEY_PRIVACY) { // Privacy is a value // $property_value = intval($property_value); if ($property_value != EVENT_VALUE_EVENT_PRIVACY_PUBLIC && $property_value != EVENT_VALUE_EVENT_PRIVACY_PRIVATE) { $error = Error::withDomain(VALIDATION_ERROR_DOMAIN, VALIDATION_ERROR_CODE_INVALID_PROPERTY, $property_name . " is " . $property_value . " but needs to be '" . EVENT_VALUE_EVENT_PRIVACY_PUBLIC . "' or '" . EVENT_VALUE_EVENT_PRIVACY_PRIVATE . "'."); return false; } } return true; }
public static function propertyIsValid($property_name, &$property_value, &$error) { if ($property_name === 'rawPassword') { // Password // if (!(is_string($property_value) && preg_match('/^(?=.*\\d)(?=.*[a-z])(?=.*[A-Z]).{5,63}$/', $property_value))) { // Property is invalid // $error = Error::withDomain(VALIDATION_ERROR_DOMAIN, VALIDATION_ERROR_CODE_INVALID_PROPERTY, 'Password should be between 6 and 64 characters, with at least one capital letter and one number.'); return; } } else { // Unrecognised property name // $error = Error::withDomain(VALIDATION_ERROR_DOMAIN, VALIDATION_ERROR_CODE_UNRECOGNISED_PROPERTY_NAME, VALIDATION_ERROR_DESCRIPTION_UNRECOGNISED_PROPERTY_NAME); return false; } return true; }
public static function propertyIsValid($property_name, &$property_value, &$error) { if ($property_name === 'rawEmail') { // Email // if (!(is_string($property_value) && preg_match('/^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\\.[a-zA-Z0-9-.]+$/', $property_value))) { // Property is invalid // $error = Error::withDomain(VALIDATION_ERROR_DOMAIN, VALIDATION_ERROR_CODE_INVALID_PROPERTY, 'Invalid email.'); return; } } else { // Unrecognised property name // $error = Error::withDomain(VALIDATION_ERROR_DOMAIN, VALIDATION_ERROR_CODE_UNRECOGNISED_PROPERTY_NAME, VALIDATION_ERROR_DESCRIPTION_UNRECOGNISED_PROPERTY_NAME); return false; } return true; }
public static function propertyIsValid($property_name, &$property_value, &$error) { if ($property_name === 'rawIdentifier') { // Identification // if (!(is_string($property_value) && strlen($property_value) > 0 && preg_match('/^[a-zA-Z0-9]*$/', $property_value))) { // Not valid // $error = Error::withDomain(VALIDATION_ERROR_DOMAIN, VALIDATION_ERROR_CODE_INVALID_PROPERTY, 'Identification must be a string with a length greater than zero and consists of alphanumeric characters.'); return false; } } else { // Unrecognised property name // $error = Error::withDomain(VALIDATION_ERROR_DOMAIN, VALIDATION_ERROR_CODE_UNRECOGNISED_PROPERTY_NAME, "Invalid property name '" . $property_name . "'"); return false; } return true; }
public static function isValid(&$properties_dictionary, $limit_to_keys, &$error) { // Check each property is valid // if (ValidationC::should_test_property(EVENT_TYPE_FACTORY_KEY_EVENT_TYPE_NAME, $properties_dictionary, true, $limit_to_keys) && $properties_dictionary[EVENT_TYPE_FACTORY_KEY_EVENT_TYPE_NAME] === 'EventTypeAnniversary') { return EventTypeAnniversary::isValid($properties_dictionary, $limit_to_keys, $error); } else { if (ValidationC::should_test_property(EVENT_TYPE_FACTORY_KEY_EVENT_TYPE_NAME, $properties_dictionary, true, $limit_to_keys) && $properties_dictionary[EVENT_TYPE_FACTORY_KEY_EVENT_TYPE_NAME] === 'EventTypeAnniversaryWedding') { return EventTypeAnniversaryWedding::isValid($properties_dictionary, $limit_to_keys, $error); } else { if (ValidationC::should_test_property(EVENT_TYPE_FACTORY_KEY_EVENT_TYPE_NAME, $properties_dictionary, true, $limit_to_keys) && $properties_dictionary[EVENT_TYPE_FACTORY_KEY_EVENT_TYPE_NAME] === 'EventTypeBirthday') { return EventTypeBirthday::isValid($properties_dictionary, $limit_to_keys, $error); } else { if (ValidationC::should_test_property(EVENT_TYPE_FACTORY_KEY_EVENT_TYPE_NAME, $properties_dictionary, true, $limit_to_keys) && $properties_dictionary[EVENT_TYPE_FACTORY_KEY_EVENT_TYPE_NAME] === 'EventTypeCelebration') { return EventTypeCelebration::isValid($properties_dictionary, $limit_to_keys, $error); } else { if (ValidationC::should_test_property(EVENT_TYPE_FACTORY_KEY_EVENT_TYPE_NAME, $properties_dictionary, true, $limit_to_keys) && $properties_dictionary[EVENT_TYPE_FACTORY_KEY_EVENT_TYPE_NAME] === 'EventTypeGigMusic') { return EventTypeGigMusic::isValid($properties_dictionary, $limit_to_keys, $error); } else { if (ValidationC::should_test_property(EVENT_TYPE_FACTORY_KEY_EVENT_TYPE_NAME, $properties_dictionary, true, $limit_to_keys) && $properties_dictionary[EVENT_TYPE_FACTORY_KEY_EVENT_TYPE_NAME] === 'EventTypeGigComedy') { return EventTypeGigComedy::isValid($properties_dictionary, $limit_to_keys, $error); } else { if (ValidationC::should_test_property(EVENT_TYPE_FACTORY_KEY_EVENT_TYPE_NAME, $properties_dictionary, true, $limit_to_keys) && $properties_dictionary[EVENT_TYPE_FACTORY_KEY_EVENT_TYPE_NAME] === 'EventTypeParty') { return EventTypeParty::isValid($properties_dictionary, $limit_to_keys, $error); } else { if (ValidationC::should_test_property(EVENT_TYPE_FACTORY_KEY_EVENT_TYPE_NAME, $properties_dictionary, true, $limit_to_keys) && $properties_dictionary[EVENT_TYPE_FACTORY_KEY_EVENT_TYPE_NAME] === 'EventTypePartyLaunch') { return EventTypePartyLaunch::isValid($properties_dictionary, $limit_to_keys, $error); } else { $error = Error::withDomain(EVENT_TYPE_FACTORY_ERROR_DOMAIN, EVENT_TYPE_FACTORY_ERROR_CODE_INVALID_NAME, 'Invalid name.'); return false; } } } } } } } } return true; }
public static function destroy(Inputter $inputter, JSONOutputter $outputter) { // Create // // 1) Test all data is available and valid // // Availability // $required_dictionary = array('user_identification' => '', 'user_to_unfollow_identification' => ''); $inputter->validate_input($required_dictionary, null); // Valid // // Identifiers // $validation_error = null; UniversallyUniqueObject::propertyIsValid(UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION, $inputter->variables_array['user_identification'], $validation_error); UniversallyUniqueObject::propertyIsValid(UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION, $inputter->variables_array['user_to_unfollow_identification'], $validation_error); if (isset($validation_error)) { $outputter->print_error($validation_error); } // Different // if ($inputter->variables_array['user_identification'] === $inputter->variables_array['user_to_unfollow_identification']) { $outputter->print_error(Error::withDomain(PRIVATE_EVENTS_REST_CONTROLLER_ERROR_DOMAIN, PRIVATE_EVENTS_REST_CONTROLLER_ERROR_CODE_INPUT_NOT_UNIQUE, 'Users cannot unfollow themselves.')); } // 2) Check request we want to process CAN go ahead // // Identification should exist // $client = new Everyman\Neo4j\Client('events.sb04.stations.graphenedb.com', 24789); $client->getTransport()->setAuth('Events', '3TP9LHROhv8LIcGmbYzq'); $query_string_check_object = 'MATCH (object:AttendingUser) ' . 'WHERE object.' . UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION . " = '" . $inputter->variables_array['user_identification'] . "' " . 'RETURN object'; $query_check_object = new Everyman\Neo4j\Cypher\Query($client, $query_string_check_object); $result_check_object = $query_check_object->getResultSet(); if (!isset($result_check_object[0]['object'])) { // No user exists // $outputter->print_error(Error::withDomain(PRIVATE_EVENTS_REST_CONTROLLER_ERROR_DOMAIN, PRIVATE_EVENTS_REST_CONTROLLER_ERROR_CODE_ENTITY_DOES_NOT_EXIST, 'user_identification should be an existing user identification.')); } $client = new Everyman\Neo4j\Client('events.sb04.stations.graphenedb.com', 24789); $client->getTransport()->setAuth('Events', '3TP9LHROhv8LIcGmbYzq'); $query_string_check_object = 'MATCH (object:CreatingUser) ' . 'WHERE object.' . UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION . " = '" . $inputter->variables_array['user_to_unfollow_identification'] . "' " . 'RETURN object'; $query_check_object = new Everyman\Neo4j\Cypher\Query($client, $query_string_check_object); $result_check_object = $query_check_object->getResultSet(); if (!isset($result_check_object[0]['object'])) { // No user_to_follow_identification exists // $outputter->print_error(Error::withDomain(PRIVATE_EVENTS_REST_CONTROLLER_ERROR_DOMAIN, PRIVATE_EVENTS_REST_CONTROLLER_ERROR_CODE_ENTITY_DOES_NOT_EXIST, 'user_to_unfollow_identification should be an existing user identification.')); } // Connection might exist // $client = new Everyman\Neo4j\Client('events.sb04.stations.graphenedb.com', 24789); $client->getTransport()->setAuth('Events', '3TP9LHROhv8LIcGmbYzq'); $query_string_check_connection = 'OPTIONAL MATCH (user:AttendingUser)-[following:' . ATTENDINGUSER_RELATIONSHIP_NAME_FOLLOW . ']->(user_to_unfollow:CreatingUser)-[follower: ' . CREATINGUSER_RELATIONSHIP_NAME_FOLLOWER . ']->(user) ' . 'WHERE user.' . UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION . " = '" . $inputter->variables_array['user_identification'] . "' AND user_to_unfollow." . UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION . " = '" . $inputter->variables_array['user_to_unfollow_identification'] . "' " . 'RETURN following, follower'; $query_check_connection = new Everyman\Neo4j\Cypher\Query($client, $query_string_check_connection); $result_check_connection = $query_check_connection->getResultSet(); if (!isset($result_check_connection[0]['following']) || !isset($result_check_connection[0]['follower'])) { // At least one object exists // $outputter->print_error(Error::withDomain(PRIVATE_EVENTS_REST_CONTROLLER_ERROR_DOMAIN, PRIVATE_EVENTS_REST_CONTROLLER_ERROR_CODE_RELATIONSHIP_EXISTS, 'Connection does not exist between users.')); } // 3) We've got the go ahead to process the request as it's intended - destroy the follow connection // // Get objects // $client = new Everyman\Neo4j\Client('events.sb04.stations.graphenedb.com', 24789); $client->getTransport()->setAuth('Events', '3TP9LHROhv8LIcGmbYzq'); $query_string_users = 'MATCH (user:AttendingUser)-[following:' . ATTENDINGUSER_RELATIONSHIP_NAME_FOLLOW . ']->(user_to_unfollow:CreatingUser)-[follower:' . CREATINGUSER_RELATIONSHIP_NAME_FOLLOWER . ']->(user) ' . 'WHERE user.' . UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION . " = '" . $inputter->variables_array['user_identification'] . "' AND user_to_unfollow." . UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION . " = '" . $inputter->variables_array['user_to_unfollow_identification'] . "' " . 'RETURN user, user_to_unfollow, following, follower'; $query_users = new Everyman\Neo4j\Cypher\Query($client, $query_string_users); $result_users = $query_users->getResultSet(); $user = $result_users[0]['user']; $user_to_unfollow = $result_users[0]['user_to_unfollow']; $following_relationship = $result_users[0]['following']; $follower_relationship = $result_users[0]['follower']; // Remove relationships // $following_relationship->delete(); $follower_relationship->delete(); // 4) Output results // // Print data // $outputter->print_data(array(array("user" => AttendingUser::printer_dictionary($user), "user_to_unfollow" => CreatingUser::printer_dictionary($user_to_unfollow)))); }
protected function could_not_process_request() { $this->outputter->print_error(Error::withDomain('EventsRESTController.php', 0, 'Could not process request.')); }
protected function invalid_process_additional_argument($index) { $additional_arguments_string = ''; for ($i = 0; $i < $index + 1; $i++) { $additional_arguments_string .= $this->inputter->additional_uri_arguments[$i]; if ($i < $index) { $additional_arguments_string .= ' '; } } $error = Error::withDomain(RESTCONTROLLER_ERROR_DOMAIN, RESTCONTROLLER_ERROR_CODE_INVALID_VERB, $this->http_method . ' ' . $this->request_noun . ' ' . $this->request_verb . ' ' . $additional_arguments_string . ' isn\'t valid as additional arguments.'); $this->outputter->print_error($error); }
public static function authenticate(Inputter $inputter, JSONOutputter $outputter) { // Authenticate // // 1) Test all data is available and valid // $required_dictionary = array(USER_KEY_EMAIL => '', USER_KEY_PASSWORD => ''); $inputter->validate_input($required_dictionary, null); // Validate // // User // $user_error = null; User::propertyIsValid(USER_KEY_EMAIL, $inputter->variables_array[USER_KEY_EMAIL], $user_error); User::propertyIsValid(USER_KEY_PASSWORD, $inputter->variables_array[USER_KEY_PASSWORD], $user_error); if (isset($user_error)) { $outputter->print_error($user_error); return; } // 2) Check email and password against data store // // Query string // $client = new Everyman\Neo4j\Client('events.sb04.stations.graphenedb.com', 24789); $client->getTransport()->setAuth('Events', '3TP9LHROhv8LIcGmbYzq'); $query_string_authenticate_account = 'MATCH (user:User) ' . 'WHERE user.' . USER_KEY_EMAIL . ' = \'' . $inputter->variables_array[USER_KEY_EMAIL] . '\' ' . 'AND user.' . USER_KEY_PASSWORD . ' = \'' . $inputter->variables_array[USER_KEY_PASSWORD] . '\' ' . 'RETURN user'; $query_authenticate_account = new Everyman\Neo4j\Cypher\Query($client, $query_string_authenticate_account); // Run query // $result_authenticate_account = $query_authenticate_account->getResultSet(); if ($result_authenticate_account->count() !== 1) { $error = Error::withDomain(PRIVATE_EVENTS_REST_CONTROLLER_ERROR_DOMAIN, PRIVATE_EVENTS_REST_CONTROLLER_ERROR_CODE_ENTITY_DOES_NOT_EXIST, 'A user with that email and password does not exist.'); $outputter->print_error($error); } // 3) Output the response // $account_to_authenticate = $result_authenticate_account[0]['user']; $outputter->print_data(array(AttendingUser::printer_dictionary($account_to_authenticate))); }
public static function list_event(Inputter $inputter, JSONOutputter $outputter) { // List for event // // Verify input // $required_dictionary = array('event_identification' => ''); $inputter->validate_input($required_dictionary, null); // Validate // $event_id = $inputter->variables_array['event_identification']; $event_error = null; UniversallyUniqueIdentifier::propertyIsValid('rawIdentifier', $event_id, $event_error); if (isset($event_error)) { $outputter->print_error($event_error); } // Event ID // $client = new Everyman\Neo4j\Client('events.sb04.stations.graphenedb.com', 24789); $client->getTransport()->setAuth('Events', '3TP9LHROhv8LIcGmbYzq'); $query_string = 'MATCH (occurrence:EventSpaceTimeOccurrence)-[:event]-(event:Event), (occurrence)-[:location]-(location:Location), (occurrence)-[:confined_date]-(confinedDate:ConfinedDate), (occurrence)-[:attendees_range]-(attendeesRange:Range) ' . 'WHERE event.' . UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION . " = '" . $event_id . "' " . 'RETURN occurrence, location, confinedDate, attendeesRange'; $query = new Everyman\Neo4j\Cypher\Query($client, $query_string); $result = $query->getResultSet(); if (count($result) > 0) { $event_occurrence_prints = array(); foreach ($result as $row) { $event_occurrence_print = EventSpaceTimeOccurrence::printer_dictionary($row['occurrence']); $event_occurrence_print[SPACE_TIME_OCCURRENCE_RELATIONSHIP_NAME_LOCATION] = Location::printer_dictionary($row['location']); $event_occurrence_print[SPACE_TIME_OCCURRENCE_RELATIONSHIP_NAME_CONFINED_DATE] = ConfinedDate::printer_dictionary($row['confinedDate']); $event_occurrence_print[EVENT_SPACE_TIME_OCCURRENCE_RELATIONSHIP_NAME_RANGE] = Range::printer_dictionary($row['attendeesRange']); array_push($event_occurrence_prints, $event_occurrence_print); } // Print data // $outputter->print_data($event_occurrence_prints); } else { // Throw error, user doesn't exists // $error = Error::withDomain(PRIVATE_EVENTS_REST_CONTROLLER_ERROR_DOMAIN, PRIVATE_EVENTS_REST_CONTROLLER_ERROR_CODE_ENTITY_DOES_NOT_EXIST, 'No Event Occurrences for Event with identification ' . $event_id . ' does not exist.'); $outputter->print_error($error); } }
protected static function static_test_required_keys(array $required_keys, array $input_array, &$error) { // Loop through each required key and value // foreach ($required_keys as $key => $value) { // Check the corresponding value in the input array is not set // if (!isset($input_array[$key])) { // If it isn't set return false with a missing error // $error = Error::withDomain(INPUTTER_ERROR_DOMAIN, INPUTTER_ERROR_CODE_KEY_MISSING, 'Missing a required key: ' . $key); return false; } else { if (is_array($value) && !is_array($input_array[$key])) { // Expected an array // $error = Error::withDomain(INPUTTER_ERROR_DOMAIN, INPUTTER_ERROR_CODE_KEY_TYPES_MISMATCH, 'Expected an array for the corresponding value of ' . $key . '.'); return false; } else { if (isset($value) && is_array($value) && isset($input_array[$key]) && is_array($input_array[$key])) { // Recurse the function for sub arrays // if (!Inputter::static_test_required_keys($value, $input_array[$key], $error)) { // If we return false from this one, we've found at least one error and don't need to continue // return false; } } } } } // If we get here then it must be valid // return true; }
public static function list_invited(Inputter $inputter, JSONOutputter $outputter) { // List Invited // // Constants // $invited_user_identification = 'invited_user_identification'; // Verify input // $required_keys = array($invited_user_identification => ''); $inputter->validate_input($required_keys, null); // Validate input // $validate_error = null; UniversallyUniqueIdentifier::propertyIsValid('rawIdentifier', $inputter->variables_array[$invited_user_identification], $validate_error); if (isset($validate_error)) { $outputter->print_error($validate_error); } // Events // $client = new Everyman\Neo4j\Client('events.sb04.stations.graphenedb.com', 24789); $client->getTransport()->setAuth('Events', '3TP9LHROhv8LIcGmbYzq'); $query_string = 'MATCH (invitedUser:AttendingUser)-[:softInvitation]-(event:Event)-[:type]-(eventType:EventType) ' . 'WHERE invitedUser.' . UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION . " = '" . $inputter->variables_array[$invited_user_identification] . "' " . 'RETURN invitedUser, event, eventType'; $query = new Everyman\Neo4j\Cypher\Query($client, $query_string); $result = $query->getResultSet(); $creator = $result[0]['invitedUser']; if (count($creator) > 0) { // Compare sent data is equal to data retrieved // $events_printer_dictionaries = array(); foreach ($result as $value) { $event_print = Event::printer_dictionary($value['event']); $event_print[EVENT_RELATIONSHIP_NAME_TYPE] = EventType::printer_dictionary($value['eventType']); $event_print[EVENT_RELATIONSHIP_NAME_CREATOR] = AttendingUser::printer_dictionary($value['invitedUser']); array_push($events_printer_dictionaries, $event_print); } // Print data // $outputter->print_data($events_printer_dictionaries); } else { // Throw error, user doesn't exists // $error = Error::withDomain(PRIVATE_EVENTS_REST_CONTROLLER_ERROR_DOMAIN, PRIVATE_EVENTS_REST_CONTROLLER_ERROR_CODE_ENTITY_DOES_NOT_EXIST, 'No such user with identification ' . $invited_user_identification . '.'); $outputter->print_error($error); } }
public static function create(Inputter $inputter, JSONOutputter $outputter) { // Create // // 1) Test all data is available and valid // // Availability // $required_keys = array(LOCATION_KEY_COORDINATE_LATITUDE => '', LOCATION_KEY_COORDINATE_LONGITUDE => ''); $optional_dictionary = array(UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION => uniqid(), UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_CREATED => date('c'), UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_UPDATED => date('c')); // Validate input // $inputter->validate_input($required_keys, $optional_dictionary); // Valid // $creation_error = null; // Location // Location::isValid($inputter->variables_array, false, $creation_error); // Print error // if (isset($creation_error)) { $outputter->print_error($creation_error); return; } // 2) Check request we want to process CAN go ahead // // Location identification must not exist // $client = new Everyman\Neo4j\Client('events.sb04.stations.graphenedb.com', 24789); $client->getTransport()->setAuth('Events', '3TP9LHROhv8LIcGmbYzq'); $query_string_check_location = "MATCH (uniqueObject:UniversallyUniqueObject) " . "WHERE uniqueObject." . UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION . " = '" . $inputter->variables_array[UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION] . "' " . "RETURN uniqueObject"; $query_check_location = new Everyman\Neo4j\Cypher\Query($client, $query_string_check_location); $result_check_location = $query_check_location->getResultSet(); if ($result_check_location->count() > 0) { // Location identification exists // $identification_exists = Error::withDomain(PRIVATE_EVENTS_REST_CONTROLLER_ERROR_DOMAIN, PRIVATE_EVENTS_REST_CONTROLLER_ERROR_CODE_ENTITY_EXISTS, 'Identifier is not unique.'); $outputter->print_error($identification_exists); } // 3) We've got the go ahead to process the request as it's intended - create a new user in the data store // // Location // $location_to_create = $client->makeNode(); $location_to_create->setProperty(UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION, $inputter->variables_array[UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION]); $location_to_create->setProperty(UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_CREATED, $inputter->variables_array[UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_CREATED]); $location_to_create->setProperty(UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_UPDATED, $inputter->variables_array[UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_UPDATED]); $location_to_create->setProperty(LOCATION_KEY_COORDINATE_LATITUDE, $inputter->variables_array[LOCATION_KEY_COORDINATE_LATITUDE]); $location_to_create->setProperty(LOCATION_KEY_COORDINATE_LONGITUDE, $inputter->variables_array[LOCATION_KEY_COORDINATE_LONGITUDE]); $location_to_create->save(); // Add labels // $location_label_objects = array(); foreach (Location::labels() as $name) { array_push($location_label_objects, new Everyman\Neo4j\Label($client, $name)); } if (count($location_label_objects) > 0) { $location_to_create->addLabels($location_label_objects); } // 4) Output results // $outputter->print_data(array(Location::printer_dictionary($location_to_create))); }