Skip to content

Commit

Permalink
Recent changes from NYU
Browse files Browse the repository at this point in the history
  • Loading branch information
jmarchewka committed Sep 24, 2019
1 parent 9acae1f commit f064243
Show file tree
Hide file tree
Showing 47 changed files with 1,987 additions and 263 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,5 @@ app/config/common/security.yml
app/Resources/views/institution/*
web/css/institution/*
src/AppBundle/Form/Type/ContactFormEmailType.php
SolrIndexer.py

109 changes: 109 additions & 0 deletions SolrIndexer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<?php

#$db_output_url = '<BASE URL OF YOUR DATA CATALOG INSTALLATION>/api/dataset/all.json';
#$solr_output_url = '<BASE URL OF YOUR SOLR INSTALLATION>/solr/collection1/select/?q=*:*&wt=json';
#$solr_submit_url = '<BASE URL OF YOUR SOLR INSTALLATION>/solr/data_catalog/update/json?commit=true&overwrite=true';
#$solr_remove_url = '<BASE URL OF YOUR SOLR INSTALLATION>/solr/data_catalog/update/?commit=true';

$db_output_url = 'http://testbox1.hsls.pitt.edu/data/api/dataset/all.json';
$solr_output_url = 'http://testbox1.hsls.pitt.edu:8983/solr/collection1/select/?q=*:*&wt=json';
$solr_submit_url = 'http://testbox1.hsls.pitt.edu:8983/solr/collection1/update/json?commit=true&overwrite=true';
$solr_remove_url = 'http://testbox1.hsls.pitt.edu:8983/solr/collection1/update/?commit=true';


if (! $fh = fopen($db_output_url, 'r')) {
exit("Could not open '{$db_output_url}'\n");
}

$db_json = stream_get_contents($fh);
$db_json_parsed = json_decode($db_json);

fclose($fh);

#
# Find items to remove

if (! $fh = fopen($solr_output_url, 'r')) {
exit("Could not open '{$solr_output_url}'\n");
}

$solr_json = stream_get_contents($fh);

fclose($fh);

foreach (json_decode($solr_json)->response->docs as $row) {

$found=0;
foreach($db_json_parsed as $db_row) {

if ($row->id == $db_row->id) {
$found=1;
break;
}

}
if ($found!=1) {

$to_solr = "{'delete': {'id': ".$row->id."}}";
$context = stream_context_create([
'http' => [
'method' => 'POST',
'header' => 'Content-Type: application/json' . "\r\n"
. 'Content-Length: ' . strlen($to_solr) . "\r\n",
'content' => $to_solr,
]
]);

file_get_contents($solr_remove_url, null, $context);
print "delete ".$row->id."\n";

}

}


#
# Find new/added items

foreach ($db_json_parsed as $row) {
if ($row->dataset_end_date && $row->dataset_start_date) {
$end_date = $row->dataset_end_date;
if ('Present' == $row->dataset_end_date) {
$end_date = (int) (date('Y') + 1);
}

if ($row->dataset_start_date == $end_date) {
$row->dataset_years = ["{$row->dataset_start_date}-01-01T00:00:00Z","{$end_date}-01-01T00:00:00Z"];
}
else {
$row->dataset_years = [];
for ($i = $row->dataset_start_date; $i <= $end_date; $i++) {
$row->dataset_years[] = "{$i}-01-01T00:00:00Z";
}
}
}

foreach ($row as $k => $v) {
if (! $v) {
$row->{$k} = '';
}
}
if ($row->date_added) {
$from_symfony = $row->date_added->date;
$row->date_added = trim(explode(' ', $from_symfony)[0]) . 'T00:00:00Z';
}

$to_solr = json_encode([$row]);
echo $to_solr;

$context = stream_context_create([
'http' => [
'method' => 'POST',
'header' => 'Content-Type: application/json' . "\r\n"
. 'Content-Length: ' . strlen($to_solr) . "\r\n",
'content' => $to_solr,
]
]);

file_get_contents($solr_submit_url, null, $context);
}
1 change: 1 addition & 0 deletions app/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public function registerBundles()
new Symfony\Bundle\AsseticBundle\AsseticBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new EWZ\Bundle\RecaptchaBundle\EWZRecaptchaBundle(),
new AppBundle\AppBundle(),


Expand Down
191 changes: 108 additions & 83 deletions app/Resources/views/base.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -63,87 +63,102 @@
</head>
<body>
<a href="#maincontent" class="skip">Skip to content</a>
<div class="page-wrapper">
<header id="page-header">
<span class="logo-container">
{# tell us where your site's logo lives in 'institution/logo.html.twig' #}
{% include ['institution/logo.html.twig','logo.html.twig'] ignore missing %}
</span>
<span class="pagetitle">
<h2><a class="pagetitlelink" href="/">{{ site_name }}</a></h2>
</span>
<nav class="nav-links">
{% if is_granted('ROLE_USER') %}
<h4 id="logged-in-badge">
<a href="{{ path('admin_panel') }}"><span class="greeting label label-warning">Welcome!</span></a>
</h4>
{% endif %}
<ul class="nav nav-tabs">
<li class="home-nav-link {% if app.request.get('_route') == 'default_search_results'%}active{% endif %} "><a href="/">Home</a></li>
<li class="about-nav-link {% if app.request.get('_route') == 'about' %}active{% endif %}"><a href="{{ path('about') }}">About the Catalog</a></li>
<li class="contact-page-link {% if app.request.get('_route') == 'contact' %}active{% endif %}"><a href="{{ path('contact') }}">Contact Us</a></li>
{% if is_granted('ROLE_USER') %}
<li class="privileged-nav-link admin-page-link {% if is_granted('ROLE_USER') and adminPage is defined and adminPage==true %}active{% endif %}"><a href="{{ path('admin_panel') }}">Admin</a></li>
{% endif %}
{% if is_granted('ROLE_USER') %}
<li class="privileged-nav-link"><a href="{{ path('logout') }}">Logout</a></li>
{% else %}
<li class="login-link hidden-xs"><a href="{{ path('login_route') }}">Login</a></li>
{% endif %}

</ul>
</nav>
</header>
<div id="search-header">
<div class="row">
<p class="search-box-description">Search here to find large public and licensed datasets</p>
<form id="keyword-search-form" class="input-group">
<label for="keyword-search-input">search terms</label>
<input type="text" class="form-control" id="keyword-search-input">
<span class="input-group-btn">
<button id="keyword-search-submit" class="btn btn-default" type="submit">Go!</button>
</span>
</form>

</div><!-- /.row -->
</div>
<div id="maincontent" class="content-container">

{# ADMIN NAV SIDEBAR #}
{% if is_granted('ROLE_USER') and adminPage is defined and adminPage==true %}
<div class="admin-nav-sidebar col-xs-3">
<ul class="nav nav-stacked nav-pills">
{% if is_granted('ROLE_ADMIN') %}
<li class="{% if app.request.get('_route') == 'approval_queue' %}active{% endif %}" role="presentation">
<a href="{{ path('approval_queue') }}">View Unpublished Datasets
{{ render(controller('AppBundle:Queue:queueLength')) }}
</a>
</li>
{% endif %}
<li class="{% if app.request.get('_route') == 'add_dataset' or app.request.get('_route') =='ingest_dataset' %}active{% endif %}" role="presentation">
<a href="{{ path('add_dataset', {'entityName':'Dataset'}) }}">Add a New Dataset</a>
</li>
{% if is_granted('ROLE_ADMIN') %}
<li class="{% if 'update/Dataset' in app.request.requestUri %}active{% endif %}" role="presentation">
<a href="{{ path('update_entity', {'entityName':'Dataset'}) }}">Edit an Existing Dataset</a>
</li>
<div class="spacer25"></div>
<li class="{% if app.request.get('_route') == 'admin_manage' or ('update' in app.request.requestUri and 'update/Dataset' not in app.request.requestUri and 'update/User' not in app.request.requestUri) %}active{% endif %}" role="presentation">
<a href="{{ path('admin_manage') }}">Manage Related Entities</a>
</li>
<li class="{% if app.request.get('_route') == 'admin_users' or 'update/User' in app.request.requestUri %}active{% endif %}" role="presentation">
<a href="{{ path('admin_users') }}">Manage Website Users</a>
</li>
<div class="spacer25"></div>
<li class="{% if 'remove/Dataset' in app.request.requestUri %}active{% endif %}" role="presentation">
<a href="{{ path('remove_entity', {'entityName':'Dataset'}) }}">Remove a Dataset</a>
</li>
{% endif %}
</ul>
</div>
{% endif %}

{% block content %}{% endblock %}
<div class="container-fluid">
<div class="row upitt-header">
<div class="col-sm-12">
<a href="//pitt.edu"><img src="{{ asset('/img/institution/pitt-logo-gold.png') }}" class="pitt-logo" alt="University of Pittsburgh"></a>
</div>
</div>
<div class="row pitt-dc-header">
<div class="col-sm-6">
<img class="header-hsls-logo" src="/img/institution/HSLS-logo-only.png">
<h1 class="pdc-pagetitle">
<span class="pdc-pagetitle-primary"><a class="pagetitlelink" href="/">{{ site_name }}</a></span>
<span class="pdc-pagetitle-subheading">A project by the <a class="pagetitlelink" href="https://www.hsls.pitt.edu/">Health Sciences Library System</a></span>
</h1>
</div>
<div class="col-sm-6 nav-col">
<ul class="nav nav-tabs">
<li class="home-nav-link {% if app.request.get('_route') == 'default_search_results'%}active{% endif %} "><a href="/">Home</a></li>
<!-- Removed temporarily
<li class="about-nav-link {% if app.request.get('_route') == 'help' %}active{% endif %}"><a href="{{ path('help') }}">Help</a></li>-->
<li class="about-nav-link"><a href="{{ url('user_search_results') }}?page=1">Browse</a></li>
<li class="about-nav-link {% if app.request.get('_route') == 'about' %}active{% endif %}"><a href="{{ path('about') }}">About</a></li>
<li class="contact-page-link {% if app.request.get('_route') == 'contact' %}active{% endif %}"><a href="{{ path('contact') }}">Contact</a></li>
{% if is_granted('ROLE_USER') %}
<li class="privileged-nav-link admin-page-link {% if is_granted('ROLE_USER') and adminPage is defined and adminPage==true %}active{% endif %}"><a href="{{ path('admin_panel') }}">Admin</a></li>
{% endif %}

</ul>

</div>
</div>
<div class="row dc-search-header">
<div class="col-sm-6 flexcol vertmidcol col-desc-fr dc-search">

<label for="keyword-search-input"><a href="{{ url('user_search_results') }}?page=1" style="color: white;" >Find datasets from University of Pittsburgh Researchers</a></label>

</div>
<div class="col-sm-6 flexcol vertmidcol dc-search">

<form id="keyword-search-form" class="input-group">
<input type="text" class="form-control" id="keyword-search-input">
<span class="input-group-btn">
<button id="keyword-search-submit" class="btn btn-default" type="submit">Go!</button>
</span>
</form>

</div>
<div class="col-sm-6 flexcol vertmidcol dc-add">

<a href="{{ url('submitdataset')}}" class="link-as-button add-link">Include your dataset</a>

</div>
<div class="col-sm-6 flexcol vertmidcol col-desc-fr dc-add">



</div>

</div>
<div class="row" id="maincontent">
{# ADMIN NAV SIDEBAR #}
{% if is_granted('ROLE_USER') and adminPage is defined and adminPage==true %}
<div class="admin-nav-sidebar col-xs-3">
<ul class="nav nav-stacked nav-pills">
{% if is_granted('ROLE_ADMIN') %}
<li class="{% if app.request.get('_route') == 'approval_queue' %}active{% endif %}" role="presentation">
<a href="{{ path('approval_queue') }}">View Unpublished Datasets
{{ render(controller('AppBundle:Queue:queueLength')) }}
</a>
</li>
{% endif %}
<li class="{% if app.request.get('_route') == 'add_dataset' or app.request.get('_route') =='ingest_dataset' %}active{% endif %}" role="presentation">
<a href="{{ path('add_dataset', {'entityName':'Dataset'}) }}">Add a New Dataset</a>
</li>
{% if is_granted('ROLE_ADMIN') %}
<li class="{% if 'update/Dataset' in app.request.requestUri %}active{% endif %}" role="presentation">
<a href="{{ path('update_entity', {'entityName':'Dataset'}) }}">Edit an Existing Dataset</a>
</li>
<div class="spacer25"></div>
<li class="{% if app.request.get('_route') == 'admin_manage' or ('update' in app.request.requestUri and 'update/Dataset' not in app.request.requestUri and 'update/User' not in app.request.requestUri) %}active{% endif %}" role="presentation">
<a href="{{ path('admin_manage') }}">Manage Related Entities</a>
</li>
<li class="{% if app.request.get('_route') == 'admin_users' or 'update/User' in app.request.requestUri %}active{% endif %}" role="presentation">
<a href="{{ path('admin_users') }}">Manage Website Users</a>
</li>
<div class="spacer25"></div>
<li class="{% if 'remove/Dataset' in app.request.requestUri %}active{% endif %}" role="presentation">
<a href="{{ path('remove_entity', {'entityName':'Dataset'}) }}">Remove a Dataset</a>
</li>
{% endif %}
</ul>
</div>
{% endif %}


{% block content %}{% endblock %}
</div>
{% block javascripts %}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
Expand All @@ -159,8 +174,18 @@
</div>
<footer id="footer">

{# Use the file 'institution/footer.html.twig' for your institution-specific footer content #}
{% include ['institution/footer.html.twig','footer.html.twig'] ignore missing %}
<div class="footer-wrapper">

{# Use the file 'institution/footer.html.twig' for your institution-specific footer content #}
{% include ['institution/footer.html.twig','footer.html.twig'] ignore missing %}

{% if is_granted('ROLE_USER') %}
<a href="{{ path('logout') }}">Admin Logout</a>
{% else %}
<a href="{{ path('login_route') }}">Admin Login</a>
{% endif %}

</div>

</footer>
</body>
Expand Down
Loading

0 comments on commit f064243

Please sign in to comment.