forked from ArctosDB/arctos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCreateContainersForBarcodes.cfm
218 lines (206 loc) · 8.42 KB
/
CreateContainersForBarcodes.cfm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
<cfinclude template = "includes/_header.cfm">
<cfset title="Create Containers">
<cfsetting requesttimeout="600">
<!----
create table cf_temp_container as select * from container where 1=2;
alter table cf_temp_container drop column container_id;
alter table cf_temp_container drop column PARENT_CONTAINER_ID;
alter table cf_temp_container drop column PRINT_FG;
alter table cf_temp_container drop column NUMBER_POSITIONS;
alter table cf_temp_container drop column LOCKED_POSITION;
alter table cf_temp_container drop column BYPASSCHECK;
alter table cf_temp_container drop column WIDTH;
alter table cf_temp_container drop column HEIGHT;
alter table cf_temp_container drop column LENGTH;
alter table cf_temp_container modify barcode not null;
create or replace public synonym cf_temp_container for cf_temp_container;
grant all on cf_temp_container to manage_container;
create unique index iu_cf_temp_cntr_barcode on cf_temp_container (barcode);
drop index iu_cf_temp_cntr_barcode;
drop table cf_temp_container;
---->
<cfif action is "makeTemplate">
<cfquery name="h" datasource="user_login" username="#session.dbuser#" password="#decrypt(session.epw,session.sessionKey)#">
select * from cf_temp_container where 1=2
</cfquery>
<cfset header=h.columnlist>
<cffile action = "write"
file = "#Application.webDirectory#/download/CreateContainerTemplate.csv"
output = "#header#"
addNewLine = "no">
<cflocation url="/download.cfm?file=CreateContainerTemplate.csv" addtoken="false">
</cfif>
<!---------------------------------->
<cfif action is "nothing">
<cfquery name="buhbyt" datasource="user_login" username="#session.dbuser#" password="#decrypt(session.epw,session.sessionKey)#">
delete from cf_temp_container
</cfquery>
<cfoutput>
<p>
Before using this form, make sure that the container series (no matter how small) is in the
<a href="http://arctosdb.org/documentation/container/##purchase" class="external" target="_blank">
spreadsheet
</a> and that there are no potential conflicts with other collections.
</p>
<p>
This form has been tested to 50,000 records; with significantly more than that or a slow connection,
smaller batches may be necessary.
</p>
<p>
<a href="CreateContainersForBarcodes.cfm?action=makeTemplate">get a template</a>
</p>
<cfquery name="ctContainer_Type" datasource="user_login" username="#session.dbuser#" password="#decrypt(session.epw,session.sessionKey)#">
select container_type from ctcontainer_type where container_type like '%label%' order by container_type
</cfquery>
<cfquery name="ctinstitution_acronym" datasource="user_login" username="#session.dbuser#" password="#decrypt(session.epw,session.sessionKey)#">
select institution_acronym from collection group by institution_acronym order by institution_acronym
</cfquery>
<table border>
<tr>
<th>Field</th>
<th>Required?</th>
<th>Doc/values</th>
</tr>
<tr>
<td>CONTAINER_TYPE</td>
<td>yes</td>
<td>#valuelist(ctContainer_Type.container_type)# or "position"</td>
</tr>
<tr>
<td>LABEL</td>
<td>yes</td>
<td>
<a href="http://arctosdb.org/documentation/container/##label" class="external" target="_blank">
doc
</a>
</td>
</tr>
<tr>
<td>BARCODE</td>
<td>yes</td>
<td>
<a href="http://arctosdb.org/documentation/container/##barcode" class="external" target="_blank">
doc
</a>
</td>
</tr>
<tr>
<td>INSTITUTION_ACRONYM</td>
<td>yes</td>
<td>#valuelist(ctinstitution_acronym.institution_acronym)#</td>
</tr>
<tr>
<td>DESCRIPTION</td>
<td>no</td>
<td>
<a href="http://arctosdb.org/documentation/container/##description" class="external" target="_blank">
doc
</a>
</td>
</tr>
<tr>
<td>CONTAINER_REMARKS</td>
<td>no</td>
<td>
<a href="http://arctosdb.org/documentation/container/##remarks" class="external" target="_blank">
doc
</a>
</td>
</tr>
</table>
Upload CSV:
<cfform name="getFile" method="post" action="CreateContainersForBarcodes.cfm" enctype="multipart/form-data">
<input type="hidden" name="action" value="getFileData">
<input type="file"
name="FiletoUpload"
size="45" onchange="checkCSV(this);">
<input type="submit" value="Upload this file" class="savBtn">
</cfform>
</cfoutput>
</cfif>
<!----------------------------------------------------------------------------------->
<cfif action is "getFileData">
<cfoutput>
<cffile action="READ" file="#FiletoUpload#" variable="fileContent">
<cfset util = CreateObject("component","component.utilities")>
<cfset x=util.CSVToQuery(fileContent)>
<cfset cols=x.columnlist>
<cfset hccols="CONTAINER_TYPE,LABEL,DESCRIPTION,CONTAINER_REMARKS,BARCODE,INSTITUTION_ACRONYM">
<cfset sql="select ">
<cfloop list="#hccols#" index="l">
<cfif listfindnocase(cols,l)>
<cfset sql=sql & #l#>
<cfelse>
<cfset sql=sql & "'' as #l#">
</cfif>
<cfif l is not listlast(hccols)>
<cfset sql=sql & ",">
</cfif>
</cfloop>
<cfquery name="ss" dbtype="query">
#sql# from x
</cfquery>
<cftransaction>
<cfloop query="ss">
<cfquery name="ins" datasource="user_login" username="#session.dbuser#" password="#decrypt(session.epw,session.sessionKey)#">
insert into cf_temp_container (CONTAINER_TYPE,LABEL,DESCRIPTION,CONTAINER_REMARKS,BARCODE,INSTITUTION_ACRONYM) values ('#CONTAINER_TYPE#','#LABEL#','#DESCRIPTION#','#CONTAINER_REMARKS#','#BARCODE#','#INSTITUTION_ACRONYM#')
</cfquery>
</cfloop>
</cftransaction>
<a href="CreateContainersForBarcodes.cfm?action=validate">loaded - proceed to validate</a>
</cfoutput>
</cfif>
<!----------------------------------------------------------------------------------->
<cfif action is "validate">
<cfset p="">
<cfquery name="d" datasource="user_login" username="#session.dbuser#" password="#decrypt(session.epw,session.sessionKey)#">
select count(*) c from cf_temp_container where barcode in (select barcode from container where barcode is not null)
</cfquery>
<cfif d.c gt 0>
<cfset p=listappend(p,'Existing barcodes detected',';')>
</cfif>
<cfquery name="d" datasource="user_login" username="#session.dbuser#" password="#decrypt(session.epw,session.sessionKey)#">
select barcode, count(barcode) c from cf_temp_container group by barcode having count(barcode) > 1
</cfquery>
<cfif d.c gt 0>
<cfset p=listappend(p,'Duplicate barcodes detected',';')>
</cfif>
<cfquery name="d" datasource="user_login" username="#session.dbuser#" password="#decrypt(session.epw,session.sessionKey)#">
select count(*) c from cf_temp_container where barcode != trim(barcode)
</cfquery>
<cfif d.c gt 0>
<cfset p=listappend(p,'Untrimmed barcodes detected',';')>
</cfif>
<cfquery name="d" datasource="user_login" username="#session.dbuser#" password="#decrypt(session.epw,session.sessionKey)#">
select count(*) c from cf_temp_container where container_type != 'position' and container_type
not in (select container_type from ctcontainer_type where container_type like '%label%')
</cfquery>
<cfif d.c gt 0>
<cfset p=listappend(p,'Invalid container_type',';')>
</cfif>
<cfquery name="d" datasource="user_login" username="#session.dbuser#" password="#decrypt(session.epw,session.sessionKey)#">
select count(*) c from cf_temp_container where institution_acronym not in (select institution_acronym from collection)
</cfquery>
<cfif d.c gt 0>
<cfset p=listappend(p,'Invalid institution_acronym',';')>
</cfif>
<cfif len(p) gt 0>
<cfthrow message='#p#; this form is a very bad place to experiment'>
</cfif>
<cfquery name="d" datasource="user_login" username="#session.dbuser#" password="#decrypt(session.epw,session.sessionKey)#">
select count(*) c from cf_temp_container where barcode != LABEL
</cfquery>
<cfif d.c gt 0>
<p>
Barcode - label mismatch detected. Proceed with great caution.
</p>
</cfif>
<a href="CreateContainersForBarcodes.cfm?action=load">proceed to load</a>
</cfif>
<!------------------------------------------------>
<cfif action is "load">
<cfstoredproc procedure="batchCreateContainer" datasource="user_login" username="#session.dbuser#" password="#decrypt(session.epw,session.sessionKey)#">
</cfstoredproc>
done
</cfif>
<cfinclude template = "includes/_footer.cfm">