Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions openml_OS/models/api/v1/Api_data.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ function bootstrap($format, $segments, $request_type, $user_id) {
return;
}

if ( $segments[0] == 'edit' && $request_type == 'post') {
$this->data_edit();
return;
}

if (count($segments) == 2 && $segments[0] == 'features' && is_numeric($segments[1]) && in_array($request_type, $getpost)) {
$this->data_features($segments[1]);
return;
Expand Down Expand Up @@ -232,6 +237,81 @@ private function data_list($segs) {
$this->xmlContents('data', $this->version, array('datasets' => $datasets));
}

private function data_edit() {
// get data id
$data_id = $this->input->post('data_id');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency, it would be great if we would solve this with a XML (and new XSD) as well.

// get edit parameters as xml
$xsdFile = xsd('openml.data.edit', $this->controller, $this->version);

if($this->input->post('edit_parameters')) {
// get fields from string upload
$edit_parameters = $this->input->post('edit_parameters', false);
if(validateXml($edit_parameters, $xsdFile, $xmlErrors, false ) == false) {
$this->returnError(1060, $this->version, $this->openmlGeneralErrorCode, $xmlErrors);
return;
}
$xml = simplexml_load_string( $edit_parameters );
} elseif (isset($_FILES['edit_parameters'])) {
$uploadError = '';
$xmlErrors = '';
if (check_uploaded_file($_FILES['edit_parameters'], false, $uploadError) == false) {
$this->returnError(1061, $this->version, $this->openmlGeneralErrorCode, $uploadError);
}
// get fields from file upload
$edit_parameters = $_FILES['edit_parameters'];

if (validateXml($edit_parameters['tmp_name'], $xsdFile, $xmlErrors) == false) {
$this->returnError(1060, $this->version, $this->openmlGeneralErrorCode, $xmlErrors);
return;
}
$xml = simplexml_load_file($edit_parameters['tmp_name']);
} else {
$this->returnError(1061, $this->version);
return;
}

// create an array of update fields for the update
$update_fields = array();
foreach($xml->children('oml', true) as $input) {
// iterate over all fields, does not check for legal fields, as it wont match the xsd.
$name = $input->getName() . '';
$update_fields[$name] = $input . '';
}

// If data id is not given
if( $data_id == false ) {
$this->returnError( 1062, $this->version );
return;}
// If dataset does not exist
$dataset = $this->Dataset->getById( $data_id );
if( $dataset == false ) {
$this->returnError( 1063, $this->version );
return;
}

// If all the fields are false, there is nothing to update, return error
if(!$update_fields) {
$this->returnError( 1064, $this->version );
return;
}
// check if user owns dataset
if($dataset->uploader != $this->user_id and !$this->user_has_admin_rights) {
$this->returnError( 1065, $this->version );
return;
}

$update_result = $this->Dataset->update($data_id, $update_fields);
// If result returns error
if( $update_result == false ) {
$this->returnError( 1066, $this->version );
return;
}

// Return data id, for user to verify changes
$this->xmlContents( 'data-edit', $this->version, array( 'dataset' => $dataset ) );
}


private function data($data_id) {
if( $data_id == false ) {
$this->returnError( 110, $this->version );
Expand Down
3 changes: 3 additions & 0 deletions openml_OS/views/pages/api_new/v1/xml/data-edit.tpl.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<oml:data_edit xmlns:oml="http://openml.org/openml">
<oml:id><?php echo $dataset->did; ?></oml:id>
</oml:data_edit>
11 changes: 11 additions & 0 deletions openml_OS/views/pages/api_new/v1/xml/pre.php
Original file line number Diff line number Diff line change
Expand Up @@ -509,4 +509,15 @@
$this->apiErrors[1053] = 'Study not owned by you';
$this->apiErrors[1054] = 'Problem inserting in database';


//openml.data.edit
//openml.data.edit
$this->apiErrors[1060] = 'Problem validating edit_parameters xml';
$this->apiErrors[1061] = 'Please provide edit_parameters xml';
$this->apiErrors[1062] = 'Data ID is required';
$this->apiErrors[1063] = 'Unknown dataset';
$this->apiErrors[1064] = 'Please provide atleast one field among description, creator, contributor, collection_date, language, citation, original_data_url or paper_url to edit. ';
$this->apiErrors[1065] = 'Dataset is not owned by you';
$this->apiErrors[1066] = 'Dataset update failed';

?>
86 changes: 86 additions & 0 deletions openml_OS/views/pages/api_new/v1/xsd/openml.data.edit.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<!-- Schema for dataset edit parameters. -->

<xs:schema targetNamespace="http://openml.org/openml"
xmlns:oml="http://openml.org/openml"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<xs:element name="data_edit_parameters" type="oml:data_edit_parameters"/>
<xs:complexType name="data_edit_parameters">
<xs:sequence>
<!-- dublin core -->
<xs:element name="description" minOccurs="0" type="oml:basic_latin16384"/> <!-- Description of the dataset, given by the user who uploaded it. -->
<xs:element name="creator" minOccurs="0" maxOccurs="unbounded" type="oml:basic_latin128"/> <!-- The person who created the dataset -->
<xs:element name="contributor" minOccurs="0" maxOccurs="unbounded" type="oml:basic_latin128"/> <!-- People who contributed to the current version of the datadat (e.g. reformatting) -->
<xs:element name="collection_date" minOccurs="0" type="oml:basic_latin128"/> <!-- The date the data was originally collected, given by the uploader -->
<xs:element name="language" minOccurs="0" type="oml:casual_string128"/> <!-- Language in which the data is represented. Starts with 1 upper case letter, rest lower case, e.g. 'English' -->
<!-- other -->
<xs:element name="citation" minOccurs="0" type="oml:basic_latin1024"/> <!-- Reference(s) that should be cited when building on this data -->
<xs:element name="original_data_url" minOccurs="0" type="xs:anyURI"/> <!-- For derived data, the url to the original dataset. This can be an OpenML dataset, e.g. 'http://openml.org/d/1'. -->
<xs:element name="paper_url" minOccurs="0" type="xs:anyURI"/> <!-- Link to a paper describing the dataset -->
</xs:sequence>
</xs:complexType>

<xs:simpleType name="system_string64"> <!-- Subset on xs:string. Highly restricted form of string. URL-friendly -->
<xs:restriction base="xs:string">
<xs:pattern value="([a-zA-Z0-9_\-\.])+"/>
<xs:maxLength value="64" />
<xs:minLength value="1" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="casual_string1024"> <!-- Subset on xs:string. Highly restricted form of string. URL-friendly -->
<xs:restriction base="xs:string">
<xs:pattern value="([a-zA-Z0-9_\-\.\(\),])+"/>
<xs:maxLength value="1024" />
<xs:minLength value="1" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="casual_string128"> <!-- Subset on xs:string. Highly restricted form of string. URL-friendly -->
<xs:restriction base="xs:string">
<xs:pattern value="([a-zA-Z0-9_\-\.\(\),])+"/>
<xs:maxLength value="128" />
<xs:minLength value="1" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="casual_string64"> <!-- Subset on xs:string. Highly restricted form of string. URL-friendly -->
<xs:restriction base="xs:string">
<xs:pattern value="([a-zA-Z0-9_\-\.\(\),])+"/>
<xs:maxLength value="64" />
<xs:minLength value="1" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="basic_latin64">
<xs:restriction base="xs:string">
<xs:pattern value="\p{IsBasicLatin}*"/>
<xs:maxLength value="64" />
<xs:minLength value="1" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="basic_latin128">
<xs:restriction base="xs:string">
<xs:pattern value="\p{IsBasicLatin}*"/>
<xs:maxLength value="128" />
<xs:minLength value="1" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="basic_latin1024">
<xs:restriction base="xs:string">
<xs:pattern value="\p{IsBasicLatin}*"/>
<xs:maxLength value="1024" />
<xs:minLength value="1" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="basic_latin16384">
<xs:restriction base="xs:string">
<xs:pattern value="\p{IsBasicLatin}*"/>
<xs:maxLength value="16384" />
<xs:minLength value="1" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="access_policy">
<xs:restriction base="xs:string">
<xs:enumeration value="circles" />
<xs:enumeration value="public" />
<xs:enumeration value="private" />
</xs:restriction>
</xs:simpleType>
</xs:schema>