Browse Source

"Posting json encoded drupal nodes to the service and parsing them with

Jackson."
7.x-2.x
Daniel Lamb 10 years ago
parent
commit
e9e7a4fa4b
  1. 40
      islandora/include/fields.inc
  2. 68
      islandora/include/rdf_mapping.inc
  3. 37
      islandora/islandora.install
  4. 12
      islandora/islandora.module
  5. 32
      islandora_basic_image/islandora_basic_image.install
  6. 1
      islandora_collection/islandora_collection.info
  7. 3
      islandora_collection/islandora_collection.install
  8. 28
      islandora_collection/islandora_collection.module
  9. 23
      islandora_dc/include/fields.inc
  10. 10
      islandora_dc/islandora_dc.install
  11. 23
      islandora_mods/include/fields.inc
  12. 9
      islandora_mods/islandora_mods.install

40
islandora/include/fields.inc

@ -12,10 +12,6 @@
* The name of the bundle to give the fields. * The name of the bundle to give the fields.
*/ */
function islandora_add_fields_to_bundle($bundle_name) { function islandora_add_fields_to_bundle($bundle_name) {
// If this gets called from an install hook, we can't guarantee the t's
// existance.
$t = get_t();
// Big list of field names/labels/descriptions. // Big list of field names/labels/descriptions.
$field_data = array( $field_data = array(
ISLANDORA_TN_FIELD => array( ISLANDORA_TN_FIELD => array(
@ -42,6 +38,27 @@ function islandora_add_fields_to_bundle($bundle_name) {
$field_label = $data['label']; $field_label = $data['label'];
$field_description = $data['description']; $field_description = $data['description'];
islandora_add_field_to_bundle($bundle_name, $field_name, $field_label, $field_description);
}
}
/**
* Adds a field to a bundle.
*
* @param string $bundle_name
* The machine name of the bundle.
* @param string $field_name
* The machine name of the field.
* @param string $field_label
* The human-readable label for the field.
* @param string $field_description
* The human-readable description for the field.
*/
function islandora_add_field_to_bundle($bundle_name, $field_name, $field_label, $field_description) {
// If this gets called from an install hook, we can't guarantee the t's
// existance.
$t = get_t();
if (field_info_field($field_name)) { if (field_info_field($field_name)) {
$field_instance = array( $field_instance = array(
'field_name' => $field_name, 'field_name' => $field_name,
@ -60,4 +77,19 @@ function islandora_add_fields_to_bundle($bundle_name) {
drupal_set_message($message); drupal_set_message($message);
} }
} }
/**
* Creates a field from a field definition.
*
* @param array $field_definition
* Field definition for the desired field.
*/
function islandora_create_field($field_definition) {
// If this gets called from an install hook, we can't guarantee the t's
// existance.
$t = get_t();
field_create_field($field_definition);
drupal_set_message($t("Created field @field",
array("@field" => $field_definition['field_name'])));
} }

68
islandora/include/rdf_mapping.inc

@ -16,16 +16,16 @@
* @return array * @return array
* The default RDF mapping for Islandora content types. * The default RDF mapping for Islandora content types.
*/ */
function islandora_get_default_rdf_mapping($bundle, $rdf_type) { function islandora_get_default_rdf_mapping($bundle, $rdf_types) {
return array( return array(
array( array(
'type' => 'node', 'type' => 'node',
'bundle' => $bundle, 'bundle' => $bundle,
'mapping' => array( 'mapping' => array(
'rdftype' => array($rdf_type), 'rdftype' => $rdf_types,
'uuid' => array( 'uuid' => array(
'predicates' => array('dc11:identifier'), 'predicates' => array('fedora:uuid'),
'datatype' => 'xsd:ID', 'datatype' => 'xsd:string',
), ),
ISLANDORA_FEDORA_HAS_PARENT_FIELD => array( ISLANDORA_FEDORA_HAS_PARENT_FIELD => array(
'predicates' => array('fedora:hasParent'), 'predicates' => array('fedora:hasParent'),
@ -35,66 +35,6 @@ function islandora_get_default_rdf_mapping($bundle, $rdf_type) {
'predicates' => array('pcdm:hasMember'), 'predicates' => array('pcdm:hasMember'),
'datatype' => 'xsd:string', 'datatype' => 'xsd:string',
), ),
ISLANDORA_DC_CONTRIBUTOR_FIELD => array(
'predicates' => array('dc11:contributor'),
'datatype' => 'xsd:string',
),
ISLANDORA_DC_COVERAGE_FIELD => array(
'predicates' => array('dc11:coverage'),
'datatype' => 'xsd:string',
),
ISLANDORA_DC_CREATOR_FIELD => array(
'predicates' => array('dc11:creator'),
'datatype' => 'xsd:string',
),
ISLANDORA_DC_DATE_FIELD => array(
'predicates' => array('dc11:date'),
'datatype' => 'xsd:string',
),
ISLANDORA_DC_DESCRIPTION_FIELD => array(
'predicates' => array('dc11:description'),
'datatype' => 'xsd:string',
),
ISLANDORA_DC_FORMAT_FIELD => array(
'predicates' => array('dc11:format'),
'datatype' => 'xsd:string',
),
ISLANDORA_DC_IDENTIFIER_FIELD => array(
'predicates' => array('dc11:identifier'),
'datatype' => 'xsd:string',
),
ISLANDORA_DC_LANGUAGE_FIELD => array(
'predicates' => array('dc11:language'),
'datatype' => 'xsd:string',
),
ISLANDORA_DC_PUBLISHER_FIELD => array(
'predicates' => array('dc11:publisher'),
'datatype' => 'xsd:string',
),
ISLANDORA_DC_RELATION_FIELD => array(
'predicates' => array('dc11:relation'),
'datatype' => 'xsd:string',
),
ISLANDORA_DC_RIGHTS_FIELD => array(
'predicates' => array('dc11:rights'),
'datatype' => 'xsd:string',
),
ISLANDORA_DC_SOURCE_FIELD => array(
'predicates' => array('dc11:source'),
'datatype' => 'xsd:string',
),
ISLANDORA_DC_SUBJECT_FIELD => array(
'predicates' => array('dc11:subject'),
'datatype' => 'xsd:string',
),
ISLANDORA_DC_TITLE_FIELD => array(
'predicates' => array('dc11:title'),
'datatype' => 'xsd:string',
),
ISLANDORA_DC_TYPE_FIELD => array(
'predicates' => array('dc11:type'),
'datatype' => 'xsd:string',
),
), ),
), ),
); );

37
islandora/islandora.install

@ -11,37 +11,28 @@
* Defines common fields for various bundles. * Defines common fields for various bundles.
*/ */
function islandora_install() { function islandora_install() {
$t = get_t(); module_load_include('inc', 'islandora', 'include/fields');
$tn_field = array( $fields = array(
array(
'field_name' => ISLANDORA_TN_FIELD, 'field_name' => ISLANDORA_TN_FIELD,
'type' => 'image', 'type' => 'image',
); ),
field_create_field($tn_field); array(
drupal_set_message($t("Created field @field",
array("@field" => ISLANDORA_TN_FIELD)));
$fedora_path_field = array(
'field_name' => ISLANDORA_FEDORA_PATH_FIELD, 'field_name' => ISLANDORA_FEDORA_PATH_FIELD,
'type' => 'text', 'type' => 'text',
); ),
field_create_field($fedora_path_field); array(
drupal_set_message($t("Created field @field",
array("@field" => ISLANDORA_FEDORA_PATH_FIELD)));
$fedora_has_parent_field = array(
'field_name' => ISLANDORA_FEDORA_HAS_PARENT_FIELD, 'field_name' => ISLANDORA_FEDORA_HAS_PARENT_FIELD,
'type' => 'text', 'type' => 'text',
); ),
field_create_field($fedora_has_parent_field); array(
drupal_set_message($t("Created field @field",
array("@field" => ISLANDORA_FEDORA_HAS_PARENT_FIELD)));
$pcdm_has_member_field = array(
'field_name' => ISLANDORA_PCDM_HAS_MEMBER_FIELD, 'field_name' => ISLANDORA_PCDM_HAS_MEMBER_FIELD,
'type' => 'text', 'type' => 'text',
),
); );
field_create_field($pcdm_has_member_field);
drupal_set_message($t("Created field @field", foreach ($fields as $field) {
array("@field" => ISLANDORA_PCDM_HAS_MEMBER_FIELD))); islandora_create_field($field);
}
} }

12
islandora/islandora.module

@ -6,8 +6,13 @@
*/ */
define('ISLANDORA_NAMESPACE', 'http://islandora.ca/ontology/v2/'); define('ISLANDORA_NAMESPACE', 'http://islandora.ca/ontology/v2/');
define('ISLANDORA_NAMESPACE_PREFIX', 'islandora');
define('ISLANDORA_FEDORA_NAMESPACE', 'http://fedora.info/definitions/v4/repository#'); define('ISLANDORA_FEDORA_NAMESPACE', 'http://fedora.info/definitions/v4/repository#');
define('ISLANDORA_FEDORA_NAMESPACE_PREFIX', 'fedora');
define('ISLANDORA_PCDM_NAMESPACE', 'http://pcdm.org/models#'); define('ISLANDORA_PCDM_NAMESPACE', 'http://pcdm.org/models#');
define('ISLANDORA_PCDM_NAMESPACE_PREFIX', 'pcdm');
define('ISLANDORA_NFO_NAMESPACE', 'http://www.semanticdesktop.org/ontologies/2007/03/22/nfo/v1.2/');
define('ISLANDORA_NFO_NAMESPACE_PREFIX', 'nfo');
define('ISLANDORA_TN_FIELD', 'field_tn'); define('ISLANDORA_TN_FIELD', 'field_tn');
define('ISLANDORA_FEDORA_PATH_FIELD', 'field_fedora_path'); define('ISLANDORA_FEDORA_PATH_FIELD', 'field_fedora_path');
define('ISLANDORA_FEDORA_HAS_PARENT_FIELD', 'field_fedora_has_parent'); define('ISLANDORA_FEDORA_HAS_PARENT_FIELD', 'field_fedora_has_parent');
@ -29,9 +34,10 @@ function islandora_ctools_plugin_api($owner, $api) {
*/ */
function islandora_rdf_namespaces() { function islandora_rdf_namespaces() {
return array( return array(
'islandora' => ISLANDORA_NAMESPACE, ISLANDORA_NAMESPACE_PREFIX => ISLANDORA_NAMESPACE,
'fedora' => ISLANDORA_FEDORA_NAMESPACE, ISLANDORA_FEDORA_NAMESPACE_PREFIX => ISLANDORA_FEDORA_NAMESPACE,
'pcdm' => ISLANDORA_PCDM_NAMESPACE, ISLANDORA_PCDM_NAMESPACE_PREFIX => ISLANDORA_PCDM_NAMESPACE,
ISLANDORA_NFO_NAMESPACE_PREFIX => ISLANDORA_NFO_NAMESPACE,
); );
} }

32
islandora_basic_image/islandora_basic_image.install

@ -14,34 +14,14 @@ function islandora_basic_image_install() {
// Ensure the basic image node type is available. // Ensure the basic image node type is available.
node_types_rebuild(); node_types_rebuild();
$t = get_t(); // Add default islandora fields.
islandora_add_fields_to_bundle(ISLANDORA_BASIC_IMAGE_CONTENT_TYPE);
// Create medium size field. // Create medium size field and add to bundle.
$medium_size_field = array( islandora_create_field(array(
'field_name' => ISLANDORA_BASIC_IMAGE_MEDIUM_SIZE_FIELD, 'field_name' => ISLANDORA_BASIC_IMAGE_MEDIUM_SIZE_FIELD,
'type' => 'image', 'type' => 'image',
); ));
field_create_field($medium_size_field); islandora_add_field_to_bundle(ISLANDORA_BASIC_IMAGE_CONTENT_TYPE, ISLANDORA_BASIC_IMAGE_MEDIUM_SIZE_FIELD, "Medium Size", "A display copy of the image");
drupal_set_message($t("Created field @field",
array("@field" => ISLANDORA_BASIC_IMAGE_MEDIUM_SIZE_FIELD)));
// Add fields instances to bundle.
if (field_info_field(ISLANDORA_BASIC_IMAGE_MEDIUM_SIZE_FIELD)) {
$medium_size_field_instance = array(
'field_name' => ISLANDORA_BASIC_IMAGE_MEDIUM_SIZE_FIELD,
'entity_type' => 'node',
'bundle' => ISLANDORA_BASIC_IMAGE_CONTENT_TYPE,
'label' => $t("Medium Size"),
'description' => $t("A display copy of the image."),
'required' => FALSE,
);
field_create_instance($medium_size_field_instance);
drupal_set_message($t('Field @name was successfully added to @bundle',
array(
'@name' => ISLANDORA_BASIC_IMAGE_MEDIUM_SIZE_FIELD,
'@bundle' => ISLANDORA_BASIC_IMAGE_CONTENT_TYPE,
)));
}
islandora_add_fields_to_bundle(ISLANDORA_BASIC_IMAGE_CONTENT_TYPE);
} }

1
islandora_collection/islandora_collection.info

@ -4,3 +4,4 @@ package = Islandora
version = 7.x-dev version = 7.x-dev
core = 7.x core = 7.x
dependencies[] = islandora dependencies[] = islandora
dependencies[] = hook_post_action

3
islandora_collection/islandora_collection.install

@ -17,7 +17,4 @@ function islandora_collection_install() {
// Add default Islandora fields. // Add default Islandora fields.
islandora_add_fields_to_bundle(ISLANDORA_COLLECTION_CONTENT_TYPE); islandora_add_fields_to_bundle(ISLANDORA_COLLECTION_CONTENT_TYPE);
// Create the pcdm:hasMember relation.
islandora_collection_define_relations();
} }

28
islandora_collection/islandora_collection.module

@ -47,15 +47,35 @@ function islandora_collection_rdf_mapping() {
} }
/** /**
* Implements hook_insert(). * Implements hook_node_postinsert().
*/ */
function islandora_collection_insert($node) { function islandora_collection_node_postinsert($node) {
// Exit early if it's not a collection.
if (strcmp($node->type, ISLANDORA_COLLECTION_CONTENT_TYPE) != 0) {
return;
}
$nodes = entity_uuid_load('node', array($node->uuid));
// Exit early if the node never was successfully inserted in the database.
if (empty($nodes)) {
return;
}
$node = array_pop($nodes);
$response = drupal_http_request("http://localhost:8080/islandora-services/rest/collection",
array(
'method' => 'POST',
'data' => json_encode($node),
));
dd("RESPONSE");
dd($response->data);
} }
/** /**
* Implements hook_update(). * Implements hook_update().
*/ */
function islandora_collection_update($node) { function islandora_collection_node_postupdate($node) {
dd("FROM POST UPDATE HOOK");
} }

23
islandora_dc/include/fields.inc

@ -12,10 +12,7 @@
* The name of the bundle to give the fields. * The name of the bundle to give the fields.
*/ */
function islandora_dc_add_fields_to_bundle($bundle_name) { function islandora_dc_add_fields_to_bundle($bundle_name) {
module_load_include('inc', 'islandora', 'include/fields');
// If this gets called from an install hook, we can't guarantee the t's
// existance.
$t = get_t();
// Big list of field names/labels/descriptions. // Big list of field names/labels/descriptions.
$field_data = array( $field_data = array(
@ -86,22 +83,6 @@ function islandora_dc_add_fields_to_bundle($bundle_name) {
$field_label = $data['label']; $field_label = $data['label'];
$field_description = $data['description']; $field_description = $data['description'];
if (field_info_field($field_name)) { islandora_add_field_to_bundle($bundle_name, $field_name, $field_label, $field_description);
$field_instance = array(
'field_name' => $field_name,
'entity_type' => 'node',
'bundle' => $bundle_name,
'label' => $t("@label", array("@description" => $field_label)),
'description' => $t("@description", array("@description" => $field_description)),
'required' => FALSE,
);
field_create_instance($field_instance);
$message = $t('Field @name was successfully added to @bundle',
array(
'@name' => $field_name,
'@bundle' => $bundle_name,
));
drupal_set_message($message);
}
} }
} }

10
islandora_dc/islandora_dc.install

@ -11,7 +11,7 @@
* Creates shared fields for content types using DC metadata. * Creates shared fields for content types using DC metadata.
*/ */
function islandora_dc_install() { function islandora_dc_install() {
$t = get_t(); module_load_include('inc', 'islandora', 'include/fields');
$field_names = array( $field_names = array(
ISLANDORA_DC_CONTRIBUTOR_FIELD, ISLANDORA_DC_CONTRIBUTOR_FIELD,
@ -32,13 +32,11 @@ function islandora_dc_install() {
); );
foreach ($field_names as $field_name) { foreach ($field_names as $field_name) {
$field = array( islandora_create_field(array(
'field_name' => $field_name, 'field_name' => $field_name,
'type' => 'text_long', 'type' => 'text_long',
'cardinality' => FIELD_CARDINALITY_UNLIMITED, 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
); ));
field_create_field($field);
drupal_set_message($t("Created field @field",
array("@field" => $field_name)));
} }
} }

23
islandora_mods/include/fields.inc

@ -12,25 +12,6 @@
* The name of the bundle to give the fields. * The name of the bundle to give the fields.
*/ */
function islandora_mods_add_fields_to_bundle($bundle_name) { function islandora_mods_add_fields_to_bundle($bundle_name) {
// If this gets called from an install hook, we can't guarantee the t's module_load_include('inc', 'islandora', 'include/fields');
// existance. islandora_add_field_to_bundle($bundle_name, ISLANDORA_MODS_FIELD, "MODS XML", "A MODS record for the Fedora resource");
$t = get_t();
if (field_info_field(ISLANDORA_MODS_FIELD)) {
$mods_field_instance = array(
'field_name' => ISLANDORA_MODS_FIELD,
'entity_type' => 'node',
'bundle' => $bundle_name,
'label' => $t("MODS XML"),
'description' => $t("A MODS record for the Fedora resource"),
'required' => FALSE,
);
field_create_instance($mods_field_instance);
$message = $t('Field @name was successfully added to @bundle',
array(
'@name' => ISLANDORA_MODS_FIELD,
'@bundle' => $bundle_name,
));
drupal_set_message($message);
}
} }

9
islandora_mods/islandora_mods.install

@ -11,13 +11,10 @@
* Creates shared fields for content types using MODS metadata. * Creates shared fields for content types using MODS metadata.
*/ */
function islandora_mods_install() { function islandora_mods_install() {
$t = get_t(); module_load_include('inc', 'islandora', 'include/fields');
$mods_field = array( islandora_create_field(array(
'field_name' => ISLANDORA_MODS_FIELD, 'field_name' => ISLANDORA_MODS_FIELD,
'type' => 'xml_field_xml', 'type' => 'xml_field_xml',
); ));
field_create_field($mods_field);
drupal_set_message($t("Created field @field",
array("@field" => ISLANDORA_MODS_FIELD)));
} }

Loading…
Cancel
Save