Commit f697dac59898723a280fb4ad9375f545c2a3e6f8

Authored by kevin_fourie
1 parent e456bb95

Merged in from DEV trunk...

WSA-72
"Add missing fields to document detail structure in web services"
Updated.

Committed By: Conrad Vermeulen
Reviewed By: Megan Watson

KTS-2730
"When adding a document, the document util's add function dies on encountering an unlink"
Updated.

Committed By: Conrad Vermeulen
Reviewed By: Megan Watson

WSA-49
"Add missing fields to search structure in web services"
Updated.

Committed By: Conrad Vermeulen
Reviewed By: Kevin Fourie

WSA-78
"download manager does not construct a full url for the webservice download"
Fixed.

Committed By: Conrad Vermeulen
Reviewed By: Martin Kirsten

KTS-2734
"sanitize to html removes information from data stored in the database. It was discovered that slashes were removed"
Updated.

Committed By: Conrad Vermeulen
Reviewed By: Philip Arckoll

KTS-2735
"Metadata values should not be sanitized until display on whichever interface."
Updated.

Committed By: Conrad Vermeulen
Reviewed By: Philip Arckoll

WSA-76
"Update unit tests for document detail in web service"
Updated. Added missing fields.

WSA-79
"cater for custom_document_no and oem_document_id in webservices"
Updated. Added placeholders for future use.

Committed By: Conrad Vermeulen
Reviewed By: Kevin Fourie


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/STABLE/branches/3.4.5-Release-Branch@7766 c91229c3-7414-0410-bfa2-8a42b809f60b
ktapi/KTAPIDocument.inc.php
1   -<?
  1 +<?php
2 2 /**
3 3 * $Id$
4 4 *
5   - * The contents of this file are subject to the KnowledgeTree Public
6   - * License Version 1.1.2 ("License"); You may not use this file except in
7   - * compliance with the License. You may obtain a copy of the License at
8   - * http://www.knowledgetree.com/KPL
  5 + * KnowledgeTree Open Source Edition
  6 + * Document Management Made Simple
  7 + * Copyright (C) 2004 - 2007 The Jam Warehouse Software (Pty) Limited
9 8 *
10 9 * Software distributed under the License is distributed on an "AS IS"
11 10 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
... ... @@ -255,7 +254,7 @@ class KTAPI_Document extends KTAPI_FolderItem
255 254 return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR,$res);
256 255 }
257 256  
258   - $oDocumentTransaction = & new DocumentTransaction($this->document, $reason, 'ktcore.transactions.force_checkin');
  257 + $oDocumentTransaction = new DocumentTransaction($this->document, $reason, 'ktcore.transactions.force_checkin');
259 258  
260 259 $res = $oDocumentTransaction->create();
261 260 if (($res === false) || PEAR::isError($res)) {
... ... @@ -274,13 +273,15 @@ class KTAPI_Document extends KTAPI_FolderItem
274 273 dcv.size,
275 274 w.name as workflow,
276 275 ws.name as workflow_state,
277   - dlt.name as link_type
  276 + dlt.name as link_type, dtl.name as document_type,
  277 + dcv.major_version, dcv.minor_version
278 278 FROM
279 279 document_link dl
280 280 INNER JOIN document_link_types dlt ON dl.link_type_id=dlt.id
281 281 INNER JOIN documents d ON dl.child_document_id=d.id
282 282 INNER JOIN document_metadata_version dmv ON d.metadata_version_id=dmv.id
283 283 INNER JOIN document_content_version dcv ON dmv.content_version_id=dcv.id
  284 + INNER JOIN document_types_lookup dtl ON dtl.id=dmv.document_type_id
284 285 LEFT OUTER JOIN workflow_documents wd ON d.id=wd.document_id
285 286 LEFT OUTER JOIN workflows w ON w.id=wd.workflow_id
286 287 LEFT OUTER JOIN workflow_states ws ON wd.state_id=ws.id
... ... @@ -308,13 +309,20 @@ class KTAPI_Document extends KTAPI_FolderItem
308 309 {
309 310 continue;
310 311 }
  312 +
  313 +
  314 +
311 315 $result[] = array(
312 316 'document_id'=>(int)$row['document_id'],
  317 + 'custom_document_no'=>'n/a',
  318 + 'oem_document_no'=>'n/a',
313 319 'title'=> $row['title'],
314   - 'size'=>(int)$row['size'],
315   - 'workflow'=>$row['workflow'],
316   - 'workflow_state'=>$row['workflow_state'],
317   - 'link_type'=>$row['link_type'],
  320 + 'document_type'=> $row['document_type'],
  321 + 'version'=> (float) ($row['major_version'] . '.' . $row['minor_version']),
  322 + 'filesize'=>(int)$row['size'],
  323 + 'workflow'=>empty($row['workflow'])?'n/a':$row['workflow'],
  324 + 'workflow_state'=>empty($row['workflow_state'])?'n/a':$row['workflow_state'],
  325 + 'link_type'=>empty($row['link_type'])?'unknown':$row['link_type'],
318 326 );
319 327 }
320 328  
... ... @@ -423,7 +431,7 @@ class KTAPI_Document extends KTAPI_FolderItem
423 431 return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR,$res );
424 432 }
425 433  
426   - $oDocumentTransaction = & new DocumentTransaction($this->document, $reason, 'ktcore.transactions.permissions_change');
  434 + $oDocumentTransaction = new DocumentTransaction($this->document, $reason, 'ktcore.transactions.permissions_change');
427 435  
428 436 $res = $oDocumentTransaction->create();
429 437 if (($res === false) || PEAR::isError($res)) {
... ... @@ -441,6 +449,7 @@ class KTAPI_Document extends KTAPI_FolderItem
441 449 * @param string $reason
442 450 * @param string $newname
443 451 * @param string $newfilename
  452 + * @return KTAPI_Document
444 453 */
445 454 function copy(&$ktapi_target_folder, $reason, $newname=null, $newfilename=null)
446 455 {
... ... @@ -527,12 +536,14 @@ class KTAPI_Document extends KTAPI_FolderItem
527 536 $oTrigger = new $sTrigger;
528 537 $aInfo = array(
529 538 'document' => $new_document,
530   - 'old_folder' => $this->folder->get_folder(),
  539 + 'old_folder' => $this->ktapi_folder->get_folder(),
531 540 'new_folder' => $target_folder,
532 541 );
533 542 $oTrigger->setInfo($aInfo);
534 543 $ret = $oTrigger->postValidate();
535 544 }
  545 +
  546 + return KTAPI_Document::get($this->ktapi, $new_document->getId());
536 547 }
537 548  
538 549 /**
... ... @@ -670,6 +681,10 @@ class KTAPI_Document extends KTAPI_FolderItem
670 681 }
671 682  
672 683 $doctypeid = KTAPI::get_documenttypeid($documenttype);
  684 + if (PEAR::isError($doctypeid))
  685 + {
  686 + return $doctypeid;
  687 + }
673 688  
674 689 if ($this->document->getDocumentTypeId() != $doctypeid)
675 690 {
... ... @@ -760,7 +775,7 @@ class KTAPI_Document extends KTAPI_FolderItem
760 775 return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR, $res);
761 776 }
762 777  
763   - $oDocumentTransaction = & new DocumentTransaction($this->document, sprintf(_kt('Document archived: %s'), $reason), 'ktcore.transactions.update');
  778 + $oDocumentTransaction = new DocumentTransaction($this->document, sprintf(_kt('Document archived: %s'), $reason), 'ktcore.transactions.update');
764 779 $oDocumentTransaction->create();
765 780  
766 781 DBUtil::commit();
... ... @@ -830,7 +845,7 @@ class KTAPI_Document extends KTAPI_FolderItem
830 845 }
831 846  
832 847 $workflowid=$this->document->getWorkflowId();
833   - if (!empty($workflowid))
  848 + if (empty($workflowid))
834 849 {
835 850 return new PEAR_Error(KTAPI_ERROR_WORKFLOW_NOT_IN_PROGRESS);
836 851 }
... ... @@ -1039,6 +1054,11 @@ class KTAPI_Document extends KTAPI_FolderItem
1039 1054 function update_metadata($metadata)
1040 1055 {
1041 1056 global $default;
  1057 + if (empty($metadata))
  1058 + {
  1059 + return;
  1060 + }
  1061 +
1042 1062 $packed = $this->get_packed_metadata($metadata);
1043 1063  
1044 1064 DBUtil::startTransaction();
... ... @@ -1073,6 +1093,233 @@ class KTAPI_Document extends KTAPI_FolderItem
1073 1093  
1074 1094 }
1075 1095  
  1096 + /**
  1097 + * This updates the system metadata on the document.
  1098 + *
  1099 + * @param array $sysdata
  1100 + */
  1101 + function update_sysdata($sysdata)
  1102 + {
  1103 + if (empty($sysdata))
  1104 + {
  1105 + return;
  1106 + }
  1107 + $owner_mapping = array(
  1108 + 'created_by'=>'creator_id',
  1109 + 'modified_by'=>'modified_user_id',
  1110 + 'owner'=>'owner_id'
  1111 + );
  1112 +
  1113 + $documents = array();
  1114 + $document_content = array();
  1115 +
  1116 + foreach($sysdata as $rec)
  1117 + {
  1118 + if (is_object($rec))
  1119 + {
  1120 + $name = $rec->name;
  1121 + $value = sanitizeForSQL($rec->value);
  1122 + }
  1123 + elseif(is_array($rec))
  1124 + {
  1125 + $name = $rec['name'];
  1126 + $value = sanitizeForSQL($rec['value']);
  1127 + }
  1128 + else
  1129 + {
  1130 + // just ignore
  1131 + continue;
  1132 + }
  1133 + switch($name)
  1134 + {
  1135 + case 'created_date':
  1136 + $documents['created'] = $value;
  1137 + break;
  1138 + case 'modified_date':
  1139 + $documents['modified'] = $value;
  1140 + break;
  1141 + case 'is_immutable':
  1142 + $documents['immutable'] = in_array(strtolower($value), array('1','true','on','yes'))?'1':'0';
  1143 + break;
  1144 + case 'filename':
  1145 + $document_content['filename'] = $value;
  1146 + break;
  1147 + case 'major_version':
  1148 + $document_content['major_version'] = $value;
  1149 + break;
  1150 + case 'minor_version':
  1151 + $document_content['minor_version'] = $value;
  1152 + break;
  1153 + case 'version':
  1154 + $version = number_format($value + 0,5);
  1155 + list($major_version, $minor_version) = explode('.', $version);
  1156 + $document_content['major_version'] = $major_version;
  1157 + $document_content['minor_version'] = $minor_version;
  1158 + break;
  1159 + case 'mime_type':
  1160 + $sql = "select id from mime_types where mimetypes='$value'";
  1161 + $value = DBUtil::getResultArray($sql);
  1162 + if (PEAR::isError($value))
  1163 + {
  1164 + return $value;
  1165 + }
  1166 + if (count($value) == 0)
  1167 + {
  1168 + break;
  1169 + }
  1170 + $value = $value[0]['id'];
  1171 + $document_content['mime_id'] = $value;
  1172 + break;
  1173 + case 'owner':
  1174 + case 'created_by':
  1175 + case 'modified_by':
  1176 + $sql = "select id from users where name='$value'";
  1177 + $userId = DBUtil::getResultArray($sql);
  1178 + if (PEAR::isError($userId))
  1179 + {
  1180 + return $userId;
  1181 + }
  1182 + if (empty($userId))
  1183 + {
  1184 + $sql = "select id from users where username='$value'";
  1185 + $userId = DBUtil::getResultArray($sql);
  1186 + if (PEAR::isError($userId))
  1187 + {
  1188 + return $userId;
  1189 + }
  1190 + }
  1191 + if (empty($userId))
  1192 + {
  1193 + // if not found, not much we can do
  1194 + break;
  1195 + }
  1196 + $userId=$userId[0];
  1197 + $userId=$userId['id'];
  1198 +
  1199 + $name = $owner_mapping[$name];
  1200 + $documents[$name] = $userId;
  1201 + break;
  1202 + default:
  1203 + // TODO: we should do some logging
  1204 + //return new PEAR_Error('Unexpected field: ' . $name);
  1205 + }
  1206 + }
  1207 +
  1208 + if (count($documents) > 0)
  1209 + {
  1210 + $sql = "UPDATE documents SET ";
  1211 + $i=0;
  1212 + foreach($documents as $name=>$value)
  1213 + {
  1214 + if ($i++ > 0) $sql .= ",";
  1215 + if (is_numeric($value))
  1216 + $sql .= "$name=$value";
  1217 + else
  1218 + $sql .= "$name='$value'";
  1219 + }
  1220 + $sql .= " WHERE id=$this->documentid";
  1221 + $result = DBUtil::runQuery($sql);
  1222 + if (PEAR::isError($result))
  1223 + {
  1224 + return $result;
  1225 + }
  1226 + }
  1227 + if (count($document_content) > 0)
  1228 + {
  1229 + $content_id = $this->document->getContentVersionId();
  1230 + $sql = "UPDATE document_content_version SET ";
  1231 + $i=0;
  1232 + foreach($document_content as $name=>$value)
  1233 + {
  1234 + if ($i++ > 0) $sql .= ",";
  1235 + $sql .= "$name='$value'";
  1236 + }
  1237 + $sql .= " WHERE id=$content_id";
  1238 + $result = DBUtil::runQuery($sql);
  1239 + if (PEAR::isError($result))
  1240 + {
  1241 + return $result;
  1242 + }
  1243 + }
  1244 + }
  1245 +
  1246 + function clearCache()
  1247 + {
  1248 + // TODO: we should only clear the cache for the document we are working on
  1249 + // this is a quick fix but not optimal!!
  1250 +
  1251 +
  1252 + $metadataid = $this->document->getMetadataVersionId();
  1253 + $contentid = $this->document->getContentVersionId();
  1254 +
  1255 + $cache = KTCache::getSingleton();
  1256 +
  1257 + $cache->remove('KTDocumentMetadataVersion/id', $metadataid);
  1258 + $cache->remove('KTDocumentContentVersion/id', $contentid);
  1259 + $cache->remove('KTDocumentCore/id', $this->documentid);
  1260 + $cache->remove('Document/id', $this->documentid);
  1261 + unset($GLOBALS['_OBJECTCACHE']['KTDocumentMetadataVersion'][$metadataid]);
  1262 + unset($GLOBALS['_OBJECTCACHE']['KTDocumentContentVersion'][$contentid]);
  1263 + unset($GLOBALS['_OBJECTCACHE']['KTDocumentCore'][$this->documentid]);
  1264 +
  1265 + $this->document = &Document::get($this->documentid);
  1266 + }
  1267 +
  1268 + function mergeWithLastMetadataVersion()
  1269 + {
  1270 + // keep latest metadata version
  1271 + $metadata_version = $this->document->getMetadataVersion();
  1272 + if ($metadata_version == 0)
  1273 + {
  1274 + // this could theoretically happen in the case we are updating metadata and sysdata, but no metadata fields are specified.
  1275 + return;
  1276 + }
  1277 +
  1278 + $metadata_id = $this->document->getMetadataVersionId();
  1279 +
  1280 + // get previous version
  1281 + $sql = "SELECT id, metadata_version FROM document_metadata_version WHERE id<$metadata_id AND document_id=$this->documentid order by id desc";
  1282 + $old = DBUtil::getResultArray($sql);
  1283 + if (is_null($old) || PEAR::isError($old))
  1284 + {
  1285 + return new PEAR_Error('Previous version could not be resolved');
  1286 + }
  1287 + // only interested in the first one
  1288 + $old=$old[0];
  1289 + $old_metadata_id = $old['id'];
  1290 + $old_metadata_version = $old['metadata_version'];
  1291 +
  1292 + DBUtil::startTransaction();
  1293 +
  1294 + // delete previous metadata version
  1295 +
  1296 + $sql = "DELETE FROM document_metadata_version WHERE id=$old_metadata_id";
  1297 + $rs = DBUtil::runQuery($sql);
  1298 + if (PEAR::isError($rs))
  1299 + {
  1300 + DBUtil::rollback();
  1301 + return $rs;
  1302 + }
  1303 +
  1304 + // make latest equal to previous
  1305 + $sql = "UPDATE document_metadata_version SET metadata_version=$old_metadata_version WHERE id=$metadata_id";
  1306 + $rs = DBUtil::runQuery($sql);
  1307 + if (PEAR::isError($rs))
  1308 + {
  1309 + DBUtil::rollback();
  1310 + return $rs;
  1311 + }
  1312 + $sql = "UPDATE documents SET metadata_version=$old_metadata_version WHERE id=$this->documentid";
  1313 + $rs = DBUtil::runQuery($sql);
  1314 + if (PEAR::isError($rs))
  1315 + {
  1316 + DBUtil::rollback();
  1317 + return $rs;
  1318 + }
  1319 + DBUtil::commit();
  1320 +
  1321 + $this->clearCache();
  1322 + }
1076 1323  
1077 1324 /**
1078 1325 * This returns a workflow transition
... ... @@ -1091,7 +1338,7 @@ class KTAPI_Document extends KTAPI_FolderItem
1091 1338 $workflowid=$this->document->getWorkflowId();
1092 1339 if (empty($workflowid))
1093 1340 {
1094   - return new PEAR_Error(KTAPI_ERROR_WORKFLOW_NOT_IN_PROGRESS);
  1341 + return array();
1095 1342 }
1096 1343  
1097 1344 $result = array();
... ... @@ -1150,94 +1397,172 @@ class KTAPI_Document extends KTAPI_FolderItem
1150 1397 */
1151 1398 function get_detail()
1152 1399 {
  1400 + global $default;
  1401 + // make sure we ge tthe latest
  1402 + $this->clearCache();
  1403 +
  1404 + $config = KTConfig::getSingleton();
  1405 + $wsversion = $config->get('webservice/version', LATEST_WEBSERVICE_VERSION);
  1406 +
1153 1407 $detail = array();
1154 1408 $document = $this->document;
1155 1409  
  1410 + // get the document id
  1411 + $detail['document_id'] = (int) $document->getId();
  1412 +
  1413 + $detail['custom_document_no'] = 'n/a';
  1414 + $detail['oem_document_no'] = 'n/a';
  1415 +
  1416 + // get the title
1156 1417 $detail['title'] = $document->getName();
1157 1418  
  1419 + // get the document type
1158 1420 $documenttypeid=$document->getDocumentTypeID();
  1421 + $documenttype = '* unknown *';
1159 1422 if (is_numeric($documenttypeid))
1160 1423 {
1161   - $documenttype = DocumentType::get($documenttypeid);
  1424 + $dt = DocumentType::get($documenttypeid);
1162 1425  
1163   - $documenttype=$documenttype->getName();
1164   - }
1165   - else
1166   - {
1167   - $documenttype = '* unknown *';
  1426 + if (!is_null($dt) && !PEAR::isError($dt))
  1427 + {
  1428 + $documenttype=$dt->getName();
  1429 + }
1168 1430 }
1169 1431 $detail['document_type'] = $documenttype;
1170 1432  
1171   - $detail['version'] = $document->getVersion();
  1433 + // get the filename
1172 1434 $detail['filename'] = $document->getFilename();
1173 1435  
1174   - $detail['created_date'] = $document->getCreatedDateTime();
  1436 + // get the filesize
  1437 + $detail['filesize'] = (int) $document->getFileSize();
1175 1438  
  1439 + // get the folder id
  1440 + $detail['folder_id'] = (int) $document->getFolderID();
  1441 +
  1442 + // get the creator
1176 1443 $userid = $document->getCreatorID();
  1444 + $username='n/a';
1177 1445 if (is_numeric($userid))
1178 1446 {
  1447 + $username = '* unknown *';
1179 1448 $user = User::get($userid);
1180   - $username=(is_null($user) || PEAR::isError($user))?'* unknown *':$user->getName();
  1449 + if (!is_null($user) && !PEAR::isError($user))
  1450 + {
  1451 + $username = $user->getName();
  1452 + }
  1453 + }
  1454 + $detail['created_by'] = $username;
  1455 +
  1456 + // get the creation date
  1457 + $detail['created_date'] = $document->getCreatedDateTime();
  1458 +
  1459 + // get the checked out user
  1460 + $userid = $document->getCheckedOutUserID();
  1461 + $username='n/a';
  1462 + if (is_numeric($userid))
  1463 + {
  1464 + $username = '* unknown *';
  1465 + $user = User::get($userid);
  1466 + if (!is_null($user) && !PEAR::isError($user))
  1467 + {
  1468 + $username = $user->getName();
  1469 + }
  1470 + }
  1471 + $detail['checked_out_by'] = $username;
  1472 +
  1473 + // get the checked out date
  1474 + list($major, $minor, $fix) = explode('.', $default->systemVersion);
  1475 + if ($major == 3 && $minor >= 5)
  1476 + {
  1477 + $detail['checked_out_date'] = $document->getCheckedOutDate();
1181 1478 }
1182 1479 else
1183 1480 {
1184   - $username='n/a';
  1481 + $detail['checked_out_date'] = $detail['modified_date'];
1185 1482 }
1186   - $detail['created_by'] = $username;
1187   - $detail['updated_date'] = $document->getLastModifiedDate();
  1483 + if (is_null($detail['checked_out_date'])) $detail['checked_out_date'] = 'n/a';
1188 1484  
  1485 + // get the modified user
1189 1486 $userid = $document->getModifiedUserId();
  1487 + $username='n/a';
1190 1488 if (is_numeric($userid))
1191 1489 {
  1490 + $username = '* unknown *';
1192 1491 $user = User::get($userid);
1193   - $username=(is_null($user) || PEAR::isError($user))?'* unknown *':$user->getName();
  1492 + if (!is_null($user) && !PEAR::isError($user))
  1493 + {
  1494 + $username = $user->getName();
  1495 + }
1194 1496 }
1195   - else
  1497 + $detail['modified_by'] = $detail['updated_by'] = $username;
  1498 +
  1499 + // get the modified date
  1500 + $detail['updated_date'] = $detail['modified_date'] = $document->getLastModifiedDate();
  1501 +
  1502 + // get the owner
  1503 + $userid = $document->getOwnerID();
  1504 + $username='n/a';
  1505 + if (is_numeric($userid))
1196 1506 {
1197   - $username='n/a';
  1507 + $username = '* unknown *';
  1508 + $user = User::get($userid);
  1509 + if (!is_null($user) && !PEAR::isError($user))
  1510 + {
  1511 + $username = $user->getName();
  1512 + }
  1513 + }
  1514 + $detail['owned_by'] = $username;
  1515 +
  1516 + // get the version
  1517 + $detail['version'] = $document->getVersion();
  1518 + if ($wsversion >= 2)
  1519 + {
  1520 + $detail['version'] = (float) $detail['version'];
1198 1521 }
1199   - $detail['updated_by'] = $username;
1200   - $detail['document_id'] = (int) $document->getId();
1201   - $detail['folder_id'] = (int) $document->getFolderID();
1202 1522  
  1523 + // check immutability
  1524 + $detail['is_immutable'] = (bool) $document->getImmutable();
  1525 +
  1526 + // check permissions
  1527 + $detail['permissions'] = 'n/a';
  1528 +
  1529 + // get workflow name
1203 1530 $workflowid = $document->getWorkflowId();
  1531 + $workflowname='n/a';
1204 1532 if (is_numeric($workflowid))
1205 1533 {
1206 1534 $workflow = KTWorkflow::get($workflowid);
1207   - $workflowname=(is_null($workflow) || PEAR::isError($workflow))?'* unknown *':$workflow->getName();
1208   - }
1209   - else
1210   - {
1211   - $workflowname='n/a';
  1535 + if (!is_null($workflow) && !PEAR::isError($workflow))
  1536 + {
  1537 + $workflowname = $workflow->getName();
  1538 + }
1212 1539 }
1213 1540 $detail['workflow'] = $workflowname;
1214 1541  
  1542 + // get the workflow state
1215 1543 $stateid = $document->getWorkflowStateId();
  1544 + $workflowstate = 'n/a';
1216 1545 if (is_numeric($stateid))
1217 1546 {
1218 1547 $state = KTWorkflowState::get($stateid);
1219   - $workflowstate=(is_null($state) || PEAR::isError($state))?'* unknown *':$state->getName();
1220   - }
1221   - else
1222   - {
1223   - $workflowstate = 'n/a';
  1548 + if (!is_null($state) && !PEAR::isError($state))
  1549 + {
  1550 + $workflowstate = $state->getName();
  1551 + }
1224 1552 }
1225 1553 $detail['workflow_state']=$workflowstate;
1226 1554  
1227   - $userid = $document->getCheckedOutUserID();
  1555 + // get the full path
  1556 + $detail['full_path'] = $this->ktapi_folder->get_full_path() . '/' . $this->get_title();
1228 1557  
1229   - if (is_numeric($userid))
1230   - {
1231   - $user = User::get($userid);
1232   - $username=(is_null($user) || PEAR::isError($user))?'* unknown *':$user->getName();
1233   - }
1234   - else
1235   - {
1236   - $username = 'n/a';
1237   - }
1238   - $detail['checkout_by'] = $username;
  1558 + // get mime info
  1559 + $mimetypeid = $document->getMimeTypeID();
  1560 + $detail['mime_type'] =KTMime::getMimeTypeName($mimetypeid);
  1561 + $detail['mime_icon_path'] =KTMime::getIconPath($mimetypeid);
  1562 + $detail['mime_display'] =KTMime::getFriendlyNameForString($detail['mime_type']);
1239 1563  
1240   - $detail['full_path'] = $this->ktapi_folder->get_full_path() . '/' . $this->get_title();
  1564 + // get the storage path
  1565 + $detail['storage_path'] = $document->getStoragePath();
1241 1566  
1242 1567 return $detail;
1243 1568 }
... ... @@ -1258,7 +1583,7 @@ class KTAPI_Document extends KTAPI_FolderItem
1258 1583 $options = array();
1259 1584  
1260 1585  
1261   - $oDocumentTransaction = & new DocumentTransaction($this->document, 'Document downloaded', 'ktcore.transactions.download', $aOptions);
  1586 + $oDocumentTransaction = new DocumentTransaction($this->document, 'Document downloaded', 'ktcore.transactions.download', $aOptions);
1262 1587 $oDocumentTransaction->create();
1263 1588 }
1264 1589  
... ... @@ -1281,6 +1606,13 @@ class KTAPI_Document extends KTAPI_FolderItem
1281 1606 return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR, $transactions );
1282 1607 }
1283 1608  
  1609 + $config = KTConfig::getSingleton();
  1610 + $wsversion = $config->get('webservice/version', LATEST_WEBSERVICE_VERSION);
  1611 + foreach($transactions as $key=>$transaction)
  1612 + {
  1613 + $transactions[$key]['version'] = (float) $transaction['version'];
  1614 + }
  1615 +
1284 1616 return $transactions;
1285 1617 }
1286 1618  
... ... @@ -1293,6 +1625,9 @@ class KTAPI_Document extends KTAPI_FolderItem
1293 1625 {
1294 1626 $metadata_versions = KTDocumentMetadataVersion::getByDocument($this->document);
1295 1627  
  1628 + $config = KTConfig::getSingleton();
  1629 + $wsversion = $config->get('webservice/version', LATEST_WEBSERVICE_VERSION);
  1630 +
1296 1631 $versions = array();
1297 1632 foreach ($metadata_versions as $version)
1298 1633 {
... ... @@ -1302,10 +1637,20 @@ class KTAPI_Document extends KTAPI_FolderItem
1302 1637  
1303 1638 $userid = $document->getModifiedUserId();
1304 1639 $user = User::get($userid);
  1640 + $username = 'Unknown';
  1641 + if (!PEAR::isError($user))
  1642 + {
  1643 + $username = is_null($user)?'n/a':$user->getName();
  1644 + }
1305 1645  
1306   - $version['user'] = $user->getName();
  1646 + $version['user'] = $username;
1307 1647 $version['metadata_version'] = $document->getMetadataVersion();
1308 1648 $version['content_version'] = $document->getVersion();
  1649 + if ($wsversion >= 2)
  1650 + {
  1651 + $version['metadata_version'] = (int) $version['metadata_version'];
  1652 + $version['content_version'] = (float) $version['content_version'];
  1653 + }
1309 1654  
1310 1655 $versions[] = $version;
1311 1656 }
... ... @@ -1325,7 +1670,7 @@ class KTAPI_Document extends KTAPI_FolderItem
1325 1670 }
1326 1671 DBUtil::startTransaction();
1327 1672  
1328   - $transaction = & new DocumentTransaction($this->document, "Document expunged", 'ktcore.transactions.expunge');
  1673 + $transaction = new DocumentTransaction($this->document, "Document expunged", 'ktcore.transactions.expunge');
1329 1674  
1330 1675 $transaction->create();
1331 1676  
... ...
ktapi/KTAPIFolder.inc.php
1   -<?
  1 +<?php
2 2 /**
3 3 * $Id$
4 4 *
... ... @@ -144,14 +144,7 @@ class KTAPI_Folder extends KTAPI_FolderItem
144 144 return (int) $this->folderid;
145 145 }
146 146  
147   - /**
148   - * This can resolve a folder relative to the current directy by name
149   - *
150   - * @access public
151   - * @param string $foldername
152   - * @return KTAPI_Folder
153   - */
154   - function &get_folder_by_name($foldername)
  147 + function &_get_folder_by_name($ktapi, $foldername, $folderid)
155 148 {
156 149 $foldername=trim($foldername);
157 150 if (empty($foldername))
... ... @@ -161,14 +154,16 @@ class KTAPI_Folder extends KTAPI_FolderItem
161 154  
162 155 $split = explode('/', $foldername);
163 156  
164   - $folderid=$this->folderid;
165 157 foreach($split as $foldername)
166 158 {
167 159 if (empty($foldername))
168 160 {
169 161 continue;
170 162 }
171   - $sql = "SELECT id FROM folders WHERE name='$foldername' and parent_id=$folderid";
  163 + $foldername = sanitizeForSQL($foldername);
  164 + $sql = "SELECT id FROM folders WHERE
  165 + (name='$foldername' and parent_id=$folderid) OR
  166 + (name='$foldername' and parent_id is null and $folderid=1)";
172 167 $row = DBUtil::getOneResult($sql);
173 168 if (is_null($row) || PEAR::isError($row))
174 169 {
... ... @@ -177,12 +172,26 @@ class KTAPI_Folder extends KTAPI_FolderItem
177 172 $folderid = $row['id'];
178 173 }
179 174  
180   - return KTAPI_Folder::get($this->ktapi, $folderid);
  175 + return KTAPI_Folder::get($ktapi, $folderid);
  176 + }
  177 +
  178 +
  179 + /**
  180 + * This can resolve a folder relative to the current directy by name
  181 + *
  182 + * @access public
  183 + * @param string $foldername
  184 + * @return KTAPI_Folder
  185 + */
  186 + function &get_folder_by_name($foldername)
  187 + {
  188 + return KTAPI_Folder::_get_folder_by_name($this->ktapi, $foldername, $this->folderid);
181 189 }
182 190  
183 191 function get_full_path()
184 192 {
185 193 $path = $this->folder->getFullPath() . '/' . $this->folder->getName();
  194 + if (substr($path,0,1) == '/') $path = substr($path,1);
186 195  
187 196 return $path;
188 197 }
... ... @@ -213,6 +222,21 @@ class KTAPI_Folder extends KTAPI_FolderItem
213 222 $ktapi_folder = $this->get_folder_by_name($foldername);
214 223 }
215 224  
  225 + $currentFolderName = $this->get_folder_name();
  226 +
  227 + if (PEAR::isError($ktapi_folder) && substr($foldername, 0, strlen($currentFolderName)) == $currentFolderName)
  228 + {
  229 + if ($currentFolderName == $foldername)
  230 + {
  231 + $ktapi_folder = $this;
  232 + }
  233 + else
  234 + {
  235 + $foldername = substr($foldername, strlen($currentFolderName)+1);
  236 + $ktapi_folder = $this->get_folder_by_name($foldername);
  237 + }
  238 + }
  239 +
216 240 if (is_null($ktapi_folder) || PEAR::isError($ktapi_folder))
217 241 {
218 242 return new KTAPI_Error(KTAPI_ERROR_FOLDER_INVALID, $ktapi_folder);
... ... @@ -275,7 +299,6 @@ class KTAPI_Folder extends KTAPI_FolderItem
275 299 return $user;
276 300 }
277 301  
278   -
279 302 function get_listing($depth=1, $what='DF')
280 303 {
281 304 if ($depth < 1)
... ... @@ -287,6 +310,9 @@ class KTAPI_Folder extends KTAPI_FolderItem
287 310 $read_permission = &KTPermission::getByName(KTAPI_PERMISSION_READ);
288 311 $folder_permission = &KTPermission::getByName(KTAPI_PERMISSION_VIEW_FOLDER);
289 312  
  313 + $config = KTConfig::getSingleton();
  314 +
  315 + $wsversion = $config->get('webservice/version', LATEST_WEBSERVICE_VERSION);
290 316  
291 317 $user = $this->ktapi->get_user();
292 318  
... ... @@ -296,23 +322,68 @@ class KTAPI_Folder extends KTAPI_FolderItem
296 322 {
297 323 $folder_children = Folder::getList(array('parent_id = ?', $this->folderid));
298 324  
299   -
300 325 foreach ($folder_children as $folder)
301 326 {
302 327 if(KTPermissionUtil::userHasPermissionOnItem($user, $folder_permission, $folder))
303 328 {
304   - $creator=$this->_resolve_user($folder->getCreatorID());
305   -
306 329 if ($depth-1 > 0)
307 330 {
308 331 $sub_folder = &$this->ktapi->get_folder_by_id($folder->getId());
309   - $items = $folder->get_listing($depth-1);
  332 + $items = $sub_folder->get_listing($depth-1);
310 333 }
311 334 else
312 335 {
313 336 $items=array();
314 337 }
315 338  
  339 + $creator=$this->_resolve_user($folder->getCreatorID());
  340 +
  341 +
  342 + if ($wsversion >= 2)
  343 + {
  344 + $contents[] = array(
  345 + 'id' => (int) $folder->getId(),
  346 + 'item_type' => 'F',
  347 +
  348 + 'custom_document_no'=>'n/a',
  349 + 'oem_document_no'=>'n/a',
  350 +
  351 + 'title' => $folder->getName(),
  352 + 'document_type' => 'n/a',
  353 + 'filename' => $folder->getName(),
  354 + 'filesize' => 'n/a',
  355 +
  356 + 'created_by' => is_null($creator)?'n/a':$creator->getName(),
  357 + 'created_date' => 'n/a',
  358 +
  359 + 'checked_out_by' => 'n/a',
  360 + 'checked_out_date' => 'n/a',
  361 +
  362 + 'modified_by' => 'n/a',
  363 + 'modified_date' => 'n/a',
  364 +
  365 + 'owned_by' => 'n/a',
  366 +
  367 + 'version' => 'n/a',
  368 +
  369 + 'is_immutable'=> 'n/a',
  370 + 'permissions' => 'n/a',
  371 +
  372 + 'workflow'=>'n/a',
  373 + 'workflow_state'=>'n/a',
  374 +
  375 + 'mime_type' => 'folder',
  376 + 'mime_icon_path' => 'folder',
  377 + 'mime_display' => 'Folder',
  378 +
  379 + 'storage_path' => 'n/a',
  380 +
  381 + 'items'=>$items,
  382 +
  383 + );
  384 + }
  385 + else
  386 + {
316 387  
317 388 $contents[] = array(
318 389 'id' => (int) $folder->getId(),
... ... @@ -332,8 +403,9 @@ class KTAPI_Folder extends KTAPI_FolderItem
332 403 'items'=>$items,
333 404 'workflow'=>'n/a',
334 405 'workflow_state'=>'n/a'
335   -
336 406 );
  407 + }
  408 +
337 409 }
338 410 }
339 411 }
... ... @@ -348,9 +420,19 @@ class KTAPI_Folder extends KTAPI_FolderItem
348 420 {
349 421 if (KTPermissionUtil::userHasPermissionOnItem($user, $read_permission, $document))
350 422 {
351   - $creator=$this->_resolve_user($document->getCreatorID());
352   - $checkedoutby=$this->_resolve_user($document->getCheckedOutUserID());
353   - $modifiedby=$this->_resolve_user($document->getCreatorID());
  423 + $created_by=$this->_resolve_user($document->getCreatorID());
  424 + $created_date = $document->getCreatedDateTime();
  425 + if (empty($created_date)) $created_date = 'n/a';
  426 +
  427 + $checked_out_by=$this->_resolve_user($document->getCheckedOutUserID());
  428 + $checked_out_date = $document->getCheckedOutDate();
  429 + if (empty($checked_out_date)) $checked_out_date = 'n/a';
  430 +
  431 + $modified_by=$this->_resolve_user($document->getCreatorID());
  432 + $modified_date = $document->getCheckedOutDate();
  433 + if (empty($modified_date)) $modified_date = 'n/a';
  434 +
  435 + $owned_by =$this->_resolve_user($document->getOwnerID());
354 436  
355 437 $mimetypeid=$document->getMimeTypeID();
356 438 if (!array_key_exists($mimetypeid, $mime_cache))
... ... @@ -368,37 +450,81 @@ class KTAPI_Folder extends KTAPI_FolderItem
368 450 }
369 451 $mimeinfo=$mime_cache[$mimetypeid];
370 452  
371   - $workflow = KTWorkflowUtil::getWorkflowForDocument($document);
  453 + $workflow='n/a';
  454 + $state='n/a';
  455 +
  456 + $wf = KTWorkflowUtil::getWorkflowForDocument($document);
372 457  
373   - if (!is_null($workflow) && !PEAR::isError($workflow))
  458 + if (!is_null($wf) && !PEAR::isError($wf))
374 459 {
375   - $workflow=$workflow->getHumanName();
  460 + $workflow=$wf->getHumanName();
376 461  
377   - $state=KTWorkflowUtil::getWorkflowStateForDocument($document);
378   - if (!is_null($state) && !PEAR::isError($state))
  462 + $ws=KTWorkflowUtil::getWorkflowStateForDocument($document);
  463 + if (!is_null($ws) && !PEAR::isError($ws))
379 464 {
380 465 $state=$state->getHumanName();
381 466 }
382   - else
383   - {
384   - $state='n/a';
385   - }
386 467 }
387   - else
  468 +
  469 + if ($wsversion >= 2)
388 470 {
389   - $workflow='n/a';
390   - $state='n/a';
  471 + $docTypeId = $document->getDocumentTypeID();
  472 + $documentType = DocumentType::get($docTypeId);
  473 +
  474 +
  475 + $contents[] = array(
  476 + 'id' => (int) $document->getId(),
  477 + 'item_type' => 'D',
  478 +
  479 + 'custom_document_no'=>'n/a',
  480 + 'oem_document_no'=>'n/a',
  481 +
  482 + 'title' => $document->getName(),
  483 + 'document_type'=>$documentType->getName(),
  484 + 'filename' => $document->getFileName(),
  485 + 'filesize' => $document->getFileSize(),
  486 +
  487 + 'created_by' => is_null($created_by)?'n/a':$created_by->getName(),
  488 + 'created_date' => $created_date,
  489 +
  490 + 'checked_out_by' => is_null($checked_out_by)?'n/a':$checked_out_by->getName(),
  491 + 'checked_out_date' => $checked_out_date,
  492 +
  493 + 'modified_by' => is_null($modified_by)?'n/a':$modified_by->getName(),
  494 + 'modified_date' => $modified_date,
  495 +
  496 + 'owned_by' => is_null($owned_by)?'n/a':$owned_by->getName(),
  497 +
  498 + 'version' => $document->getMajorVersionNumber() . '.' . $document->getMinorVersionNumber(),
  499 +
  500 + 'is_immutable'=> $document->getImmutable()?'true':'false',
  501 + 'permissions' => 'n/a',
  502 +
  503 + 'workflow'=> $workflow,
  504 + 'workflow_state'=> $state,
  505 +
  506 + 'mime_type' => $mime_cache[$mimetypeid]['type'],
  507 + 'mime_icon_path' => $mime_cache[$mimetypeid]['icon'],
  508 + 'mime_display' => $mime_cache[$mimetypeid]['display'],
  509 +
  510 + 'storage_path' => $document->getStoragePath(),
  511 +
  512 + 'items'=>array(),
  513 +
  514 + );
391 515 }
  516 + else
  517 + {
392 518  
393 519  
394 520 $contents[] = array(
395 521 'id' => (int) $document->getId(),
396 522 'item_type'=>'D',
397 523 'title'=>$document->getName(),
398   - 'creator'=>is_null($creator)?'n/a':$creator->getName(),
399   - 'checkedoutby'=>is_null($checkedoutby)?'n/a':$checkedoutby->getName(),
400   - 'modifiedby'=>is_null($modifiedby)?'n/a':$modifiedby->getName(),
401   - 'filename'=>$document->getName(),
  524 + 'creator'=>is_null($created_by)?'n/a':$created_by->getName(),
  525 + 'checkedoutby'=>is_null($checked_out_by)?'n/a':$checked_out_by->getName(),
  526 + 'modifiedby'=>is_null($modified_by)?'n/a':$modified_by->getName(),
  527 + 'filename'=>$document->getFileName(),
402 528 'size'=>$document->getFileSize(),
403 529 'major_version'=>$document->getMajorVersionNumber(),
404 530 'minor_version'=>$document->getMinorVersionNumber(),
... ... @@ -410,6 +536,8 @@ class KTAPI_Folder extends KTAPI_FolderItem
410 536 'workflow'=>$workflow,
411 537 'workflow_state'=>$state
412 538 );
  539 +
  540 + }
413 541 }
414 542 }
415 543  
... ... @@ -585,7 +713,7 @@ class KTAPI_Folder extends KTAPI_FolderItem
585 713 }
586 714  
587 715 DBUtil::startTransaction();
588   - $result = KTFolderUtil::copy($this->folder, $target_folder, $user, $reason);
  716 + $result = KTFolderUtil::move($this->folder, $target_folder, $user, $reason);
589 717  
590 718 if (PEAR::isError($result))
591 719 {
... ... @@ -651,4 +779,4 @@ class KTAPI_Folder extends KTAPI_FolderItem
651 779 }
652 780 }
653 781  
654   -?>
655 782 \ No newline at end of file
  783 +?>
... ...
ktwebservice/nunit/README 0 โ†’ 100644
  1 +GENERAL
  2 +-------
  3 +
  4 +This folder includes the Nunit unit tests to unit test web services.
  5 +
  6 +
  7 +REQUIREMENTS
  8 +------------
  9 +
  10 +The unit tests were written for NUnit. NUnit 2.2.0 was used during development.
  11 +
  12 +This framework was developed in Linux using Mono.
  13 +
  14 +DATABASE
  15 +--------
  16 +
  17 +Review helper.cs to see the configuration settings. UnixODBC is used. Sample config files:
  18 +
  19 + # odbc.ini
  20 +
  21 +[ktdms]
  22 +Driver = myodbcdriver
  23 +Description = MySQL ODBC 2.50 Driver DSN
  24 +SERVER = localhost
  25 +PORT =
  26 +Socket = /tmp/mysql.sock
  27 +USER = root
  28 +Password =
  29 +Database = ktdms
  30 +OPTION = 3
  31 +
  32 + # odbcinst.ini
  33 +[myodbcdriver]
  34 +Description = MySQL ODBC 2.50 Driver DSN
  35 +Driver = /usr/lib64/unixODBC/libmyodbc3.so
  36 +
  37 +
  38 +The document type 'NewType' must be added to the database for the document_type.cs unit test to run.
  39 +
  40 +
  41 +RUNNING THE TESTS
  42 +-----------------
  43 +
  44 +Edit the makefile to ensure that the WSDL_URL is directed to the correct location.
  45 +
  46 +A makefile is provided which can be used as follows:
  47 +
  48 +- make // will build and run the tests
  49 +
  50 +- make clean // will remove all temporary and binary files
  51 +
  52 +STATE
  53 +-----
  54 +
  55 +The states of the tests is very alpha. Some of the tests are quite complicated, so we can probably split them.
  56 +
  57 +REFERENCES
  58 +----------
  59 +
  60 +For more information:
  61 +
  62 +http://nunit.org/
  63 +http://www.mono-project.com/
  64 +http://www.unixodbc.org
... ...
ktwebservice/nunit/authentication.cs 0 โ†’ 100644
  1 +using NUnit.Framework;
  2 +using System;
  3 +using System.IO;
  4 +
  5 +namespace MonoTests.KnowledgeTree
  6 +{
  7 + [TestFixture]
  8 + public class AuthenticationTest
  9 + {
  10 +
  11 + private String _session;
  12 + private KnowledgeTreeService _kt;
  13 +
  14 + [SetUp]
  15 + public void SetUp()
  16 + {
  17 + this._kt = new KTWebService();
  18 + }
  19 +
  20 + [TearDown]
  21 + public void TearDown()
  22 + {
  23 + }
  24 +
  25 + [Test]
  26 + public void Login()
  27 + {
  28 + kt_response response = this._kt.login("admin","admin","127.0.0.1");
  29 +
  30 + Assert.AreEqual(0,response.status_code);
  31 + Assert.IsFalse(response.message == null);
  32 + Assert.IsFalse(response.message == "");
  33 +
  34 + this._session = response.message;
  35 + }
  36 +
  37 + [Test]
  38 + public void Logout()
  39 + {
  40 + kt_response response = this._kt.logout(this._session);
  41 + Assert.AreEqual(0,response.status_code);
  42 + }
  43 + }
  44 +}
... ...
ktwebservice/nunit/document_add.cs 0 โ†’ 100644
  1 +using NUnit.Framework;
  2 +using System;
  3 +using System.IO;
  4 +
  5 +namespace MonoTests.KnowledgeTree
  6 +{
  7 + [TestFixture]
  8 + public class AddDocumentTest : KTTest
  9 + {
  10 +
  11 +
  12 + private int _docId;
  13 + private int _folderId;
  14 + private String _filename;
  15 + private String _content;
  16 +
  17 + public AddDocumentTest() : base()
  18 + {
  19 + this._folderId = 1;
  20 + }
  21 +
  22 + [SetUp]
  23 + public void SetUp()
  24 + {
  25 + this._filename = Helper.isUnix()?"/tmp/kt_unit_test1.txt":"c:\\kt_unit_test1.txt";
  26 + this._content = "hello world!";
  27 +
  28 + Helper.writeFile(this._filename, this._content); }
  29 +
  30 + [TearDown]
  31 + public void TearDown()
  32 + {
  33 + Helper.deleteFile(this._filename);
  34 + }
  35 +
  36 + [Test]
  37 + public void FindDocumentBeforeAdd()
  38 + {
  39 + String filename = "Root Folder/kt test folder/kt unit test1";
  40 + if (this._verbose) System.Console.WriteLine("Finding document before add: " + filename);
  41 + kt_document_detail documentDetail = this._kt.get_document_detail_by_title(this._session, 1, filename, "");
  42 + if (0 == documentDetail.status_code)
  43 + {
  44 + if (this._verbose) System.Console.WriteLine("Found document - deleting");
  45 + kt_response response = this._kt.delete_document(this._session, documentDetail.document_id, "Delete - cleaning up before add");
  46 + Assert.AreEqual(0, response.status_code);
  47 + }
  48 + else if (this._verbose)
  49 + {
  50 + System.Console.WriteLine("document not found. that is ok!");
  51 + }
  52 + }
  53 +
  54 + [Test]
  55 + public void FindFolderBeforeAdd()
  56 + {
  57 + String folder = "Root Folder/kt test folder";
  58 + if (this._verbose) System.Console.WriteLine("Finding folder before add: " + folder);
  59 + kt_folder_detail folderDetail = this._kt.get_folder_detail_by_name(this._session, folder);
  60 + if (0 == folderDetail.status_code)
  61 + {
  62 + if (this._verbose) System.Console.WriteLine("Found folder - deleting");
  63 + kt_response response = this._kt.delete_folder(this._session, folderDetail.id, "Delete - cleaning up before add");
  64 + Assert.AreEqual(0, response.status_code);
  65 + }
  66 + else
  67 + {
  68 + if (this._verbose) System.Console.WriteLine("folder not found. that is ok!");
  69 + }
  70 + }
  71 +
  72 + [Test]
  73 + public void AddDocument()
  74 + {
  75 + String folder = "kt test folder";
  76 +
  77 + if (this._verbose) System.Console.WriteLine("Creating folder : " + folder);
  78 + kt_folder_detail folderDetail = this._kt.create_folder(this._session, 1, folder);
  79 + this._folderId = folderDetail.id;
  80 + if (this._verbose) System.Console.WriteLine("Got folder id : " + this._folderId);
  81 +
  82 + String filename = "kt unit test1";
  83 +
  84 + if (this._verbose) System.Console.WriteLine("Adding document : " + filename);
  85 +
  86 +
  87 + kt_document_detail response1 = this._kt.add_base64_document(this._session, this._folderId, filename, this._filename, "Default", Helper.ConvertFileToBase64Encoding(this._filename));
  88 +
  89 + Assert.AreEqual(0, response1.status_code);
  90 + Assert.AreEqual("kt unit test1", response1.title);
  91 + Assert.AreEqual("Default", response1.document_type);
  92 + Assert.AreEqual(0.1, response1.version);
  93 + Assert.AreEqual("kt_unit_test1.txt", response1.filename);
  94 +
  95 + Assert.IsFalse(response1.created_date == null);
  96 + Assert.IsFalse(response1.created_date == "");
  97 +
  98 + Assert.AreEqual("Administrator", response1.created_by);
  99 +
  100 + //Assert.IsTrue(response1.updated_date == null);
  101 + Assert.IsTrue("" != response1.modified_date);
  102 +
  103 + Assert.AreEqual("Administrator", response1.modified_by);
  104 +
  105 + Assert.IsTrue(response1.document_id > 0);
  106 +
  107 + Assert.AreEqual(this._folderId, response1.folder_id);
  108 +
  109 +
  110 + Assert.AreEqual("n/a",response1.workflow);
  111 +
  112 +
  113 + Assert.AreEqual("n/a",response1.workflow_state);
  114 +
  115 + Assert.AreEqual("Root Folder/" + folder + "/kt unit test1", response1.full_path);
  116 +
  117 + this._docId = response1.document_id;
  118 + }
  119 +
  120 + [Test]
  121 + public void FindDocumentBeforeDelete()
  122 + {
  123 +
  124 + if (this._verbose) System.Console.WriteLine("Find document before delete");
  125 + kt_document_detail documentDetail = this._kt.get_document_detail_by_name(this._session, 1, "Root Folder/kt test folder/kt unit test1", "T","");
  126 + Assert.AreEqual(0, documentDetail.status_code);
  127 + Assert.AreEqual(this._docId, documentDetail.document_id);
  128 +
  129 +
  130 +
  131 + if (this._verbose) System.Console.WriteLine("Find document before delete without the Root Folder's explicit naming");
  132 + documentDetail = this._kt.get_document_detail_by_title(this._session, 1, "/kt test folder/kt unit test1", "");
  133 + Assert.AreEqual(0, documentDetail.status_code);
  134 + Assert.AreEqual(this._docId, documentDetail.document_id);
  135 + }
  136 +
  137 + [Test]
  138 + public void DeleteDocument()
  139 + {
  140 + if (this._verbose) System.Console.WriteLine("Deleting document");
  141 + kt_response response = this._kt.delete_document(this._session, this._docId, "Delete - cleaning up after add");
  142 + Assert.AreEqual(0, response.status_code);
  143 + }
  144 +
  145 + [Test]
  146 + public void FindDocumentAfterDelete()
  147 + {
  148 + if (this._verbose) System.Console.WriteLine("Checking that document is gone!");
  149 +
  150 + kt_document_detail documentDetail = this._kt.get_document_detail_by_title(this._session, 1, "Root Folder/kt test folder/kt unit test1", "");
  151 + Assert.IsTrue(0 != documentDetail.status_code);
  152 + }
  153 +
  154 +
  155 +
  156 +
  157 + [Test]
  158 + public void Add2PhaseDocument()
  159 + {
  160 +
  161 +
  162 + String filename = "kt unit test31";
  163 +
  164 + if (this._verbose) System.Console.WriteLine("Adding document : " + filename);
  165 + FileUploader uploader = new FileUploader();
  166 +
  167 + uploader.upload(this._session, this._filename);
  168 + String tempname = uploader.getFilename();
  169 +
  170 + kt_document_detail response1 = this._kt.add_document(this._session, this._folderId, filename, this._filename, "Default", tempname);
  171 +
  172 + Assert.AreEqual(0, response1.status_code);
  173 + Assert.AreEqual(filename, response1.title);
  174 + Assert.AreEqual("Default", response1.document_type);
  175 + Assert.AreEqual(0.1, response1.version);
  176 + Assert.AreEqual("kt_unit_test1.txt", response1.filename);
  177 +
  178 + Assert.IsFalse(response1.created_date == null);
  179 + Assert.IsFalse(response1.created_date == "");
  180 +
  181 + Assert.AreEqual("Administrator", response1.created_by);
  182 +
  183 + //Assert.IsTrue(response1.modified_date == null);
  184 + Assert.IsTrue("" != response1.modified_date);
  185 +
  186 + Assert.AreEqual("Administrator", response1.modified_by);
  187 +
  188 + Assert.IsTrue(response1.document_id > 0);
  189 +
  190 + Assert.AreEqual(this._folderId, response1.folder_id);
  191 +
  192 +
  193 + Assert.AreEqual("n/a",response1.workflow);
  194 +
  195 +
  196 + Assert.AreEqual("n/a",response1.workflow_state);
  197 +
  198 +
  199 + this._docId = response1.document_id;
  200 +
  201 + kt_response response = this._kt.delete_document(this._session, this._docId, "Delete - cleaning up after add");
  202 + Assert.AreEqual(0, response.status_code);
  203 + }
  204 +
  205 + [Test]
  206 + public void DropFolder()
  207 + {
  208 + if (this._verbose) System.Console.WriteLine("Drop Folder!");
  209 +
  210 + kt_response documentDetail = this._kt.delete_folder(this._session, this._folderId, "delete - cleaning up");
  211 + Assert.AreEqual(0, documentDetail.status_code);
  212 + }
  213 +
  214 + }
  215 +}
... ...
ktwebservice/nunit/document_checkout.cs 0 โ†’ 100644
  1 +using NUnit.Framework;
  2 +using System;
  3 +using System.IO;
  4 +
  5 +namespace MonoTests.KnowledgeTree
  6 +{
  7 + [TestFixture]
  8 + public class CheckoutDocumentTest : KTTest
  9 + {
  10 + private int _docId;
  11 + private int _folderId;
  12 + private String _filename;
  13 + private String _content;
  14 +
  15 +
  16 + [SetUp]
  17 + public void SetUp()
  18 + {
  19 +
  20 + this._filename = Helper.isUnix()?"/tmp/kt_unit_test1.txt":"c:\\kt_unit_test1.txt";
  21 +
  22 + String filename = "kt unit test1";
  23 +
  24 + this._content = "hello world!";
  25 +
  26 + Helper.writeFile(this._filename, this._content);
  27 +
  28 +
  29 +
  30 + this._folderId = 1;
  31 +
  32 + kt_document_detail response1 = this._kt.add_base64_document(this._session, this._folderId, filename, this._filename, "Default", Helper.ConvertFileToBase64Encoding(this._filename));
  33 +
  34 + if (this._verbose && response1.status_code != 0)
  35 + {
  36 + System.Console.WriteLine("Could not create file: " + this._filename);
  37 + }
  38 + this._docId = response1.document_id;
  39 +
  40 +
  41 + }
  42 +
  43 + [TearDown]
  44 + public void TearDown()
  45 + {
  46 +
  47 + Helper.deleteFile(this._filename);
  48 +
  49 + kt_response response = this._kt.delete_document(this._session, this._docId, "Delete - cleaning up");
  50 + if (this._verbose && response.status_code != 0)
  51 + {
  52 + System.Console.WriteLine("Could not delete file: " + this._filename);
  53 + }
  54 +
  55 + }
  56 +
  57 + [Test]
  58 + public void CheckoutDocument()
  59 + {
  60 + String filename = "kt unit test1";
  61 +
  62 + if (this._verbose) System.Console.WriteLine("Checking out document : " + filename);
  63 +
  64 + kt_document_detail response = this._kt.checkout_base64_document(this._session, this._docId, "unit test - going to checkout and then undo", false);
  65 + Assert.AreEqual(0, response.status_code);
  66 + Assert.AreEqual("Administrator",response.checked_out_by);
  67 + Assert.IsTrue(null != response.checked_out_date);
  68 +
  69 + response = this._kt.undo_document_checkout(this._session, this._docId, "unit test - doing undo");
  70 + Assert.AreEqual(0, response.status_code);
  71 + Assert.AreEqual("n/a",response.checked_out_by);
  72 + Assert.AreEqual("n/a", response.checked_out_date);
  73 + }
  74 +
  75 + [Test]
  76 + public void CheckinDocument()
  77 + {
  78 + String filename = "kt unit test1";
  79 +
  80 + if (this._verbose) System.Console.WriteLine("Checking out document : " + filename);
  81 +
  82 + kt_document_detail response = this._kt.checkout_base64_document(this._session, this._docId, "unit test - going to checkout and then checkin", false);
  83 + Assert.AreEqual(0, response.status_code);
  84 + Assert.AreEqual("Administrator",response.checked_out_by);
  85 + Assert.IsTrue(null != response.checked_out_date);
  86 +
  87 +
  88 + kt_document_detail checkin = this._kt.checkin_base64_document(this._session, this._docId, filename, "unit test - doing checkin", Helper.ConvertFileToBase64Encoding(this._filename), false);
  89 + Assert.AreEqual(0, checkin.status_code);
  90 + Assert.AreEqual("n/a",checkin.checked_out_by);
  91 + Assert.AreEqual("n/a", checkin.checked_out_date);
  92 + }
  93 +
  94 + [Test]
  95 + public void Checkin2PhaseDocument()
  96 + {
  97 + String filename = "kt unit test1";
  98 +
  99 + if (this._verbose) System.Console.WriteLine("Checking out document : " + filename);
  100 +
  101 + kt_document_detail response = this._kt.checkout_document(this._session, this._docId, "unit test - going to checkout and then checkin", false);
  102 + Assert.AreEqual(0, response.status_code);
  103 + Assert.AreEqual("Administrator",response.checked_out_by);
  104 + Assert.IsTrue(null != response.checked_out_date);
  105 +
  106 + FileUploader uploader = new FileUploader();
  107 +
  108 + uploader.upload(this._session, this._filename);
  109 + String tempname = uploader.getFilename();
  110 +
  111 + kt_document_detail checkin = this._kt.checkin_document(this._session, this._docId, filename, "unit test - doing checkin", tempname, false);
  112 + Assert.AreEqual(0, checkin.status_code);
  113 + Assert.AreEqual("n/a",checkin.checked_out_by);
  114 + Assert.AreEqual("n/a", checkin.checked_out_date);
  115 + }
  116 +
  117 +
  118 +
  119 + }
  120 +}
... ...
ktwebservice/nunit/document_contents.cs 0 โ†’ 100644
  1 +using NUnit.Framework;
  2 +using System;
  3 +using System.IO;
  4 +
  5 +namespace MonoTests.KnowledgeTree
  6 +{
  7 + [TestFixture]
  8 + public class DocumentContentsTest : KTTest
  9 + {
  10 + private int _folderId;
  11 + private Document _doc1;
  12 +
  13 +
  14 + [SetUp]
  15 + public void SetUp()
  16 + {
  17 +
  18 + this._doc1 = new Document(1, this._session, this._kt, this._verbose,false);
  19 + this._doc1.createFile(1);
  20 +
  21 + kt_folder_detail response = this._kt.create_folder(this._session, 1, "kt_unit_testabc");
  22 +
  23 +
  24 + this._folderId = response.id;
  25 +
  26 + }
  27 +
  28 + [TearDown]
  29 + public void TearDown()
  30 + {
  31 + this._doc1.deleteFile();
  32 + }
  33 +
  34 + [Test]
  35 + public void Query()
  36 + {
  37 +
  38 + kt_folder_contents response = this._kt.get_folder_contents(this._session, 1, 1, "DF");
  39 +
  40 + Assert.AreEqual(0, response.status_code);
  41 + Assert.AreEqual(2, response.items.Length);
  42 +
  43 + Assert.AreEqual(this._doc1.docId, response.items[1].id);
  44 +
  45 + Assert.AreEqual("n/a", response.items[1].custom_document_no);
  46 + Assert.AreEqual("n/a", response.items[1].oem_document_no);
  47 +
  48 + Assert.AreEqual("D", response.items[1].item_type);
  49 + Assert.AreEqual(this._doc1.title, response.items[1].title);
  50 + Assert.AreEqual(this._doc1.realFilename, response.items[1].filename);
  51 + Assert.AreEqual("Default", response.items[1].document_type);
  52 + Assert.AreEqual(this._doc1.filesize+1 + "", response.items[1].filesize);
  53 +
  54 + Assert.AreEqual("Administrator", response.items[1].created_by);
  55 + Assert.AreEqual("Administrator", response.items[1].modified_by);
  56 + Assert.AreEqual("n/a", response.items[1].checked_out_by);
  57 + Assert.AreEqual("Administrator", response.items[1].owned_by);
  58 + Assert.AreEqual("0.1", response.items[1].version);
  59 + Assert.AreEqual("false", response.items[1].is_immutable);
  60 + Assert.AreEqual("n/a", response.items[1].permissions);
  61 + Assert.AreEqual("n/a", response.items[1].workflow);
  62 + Assert.AreEqual("n/a", response.items[1].workflow_state);
  63 + Assert.AreEqual("text/plain", response.items[1].mime_type);
  64 + Assert.AreEqual("text", response.items[1].mime_icon_path);
  65 + Assert.AreEqual("Plain Text", response.items[1].mime_display);
  66 + Assert.IsTrue("" != response.items[1].storage_path);
  67 +
  68 + Assert.AreEqual(this._folderId, response.items[0].id);
  69 + Assert.AreEqual("F", response.items[0].item_type);
  70 + Assert.AreEqual("kt_unit_testabc", response.items[0].title);
  71 +
  72 + Assert.AreEqual("kt_unit_testabc", response.items[0].filename);
  73 + Assert.AreEqual("n/a", response.items[0].document_type);
  74 + Assert.AreEqual("n/a", response.items[0].filesize);
  75 +
  76 + Assert.AreEqual("Administrator", response.items[0].created_by);
  77 + Assert.AreEqual("n/a", response.items[0].modified_by);
  78 + Assert.AreEqual("n/a", response.items[0].checked_out_by);
  79 + Assert.AreEqual("n/a", response.items[0].owned_by);
  80 + Assert.AreEqual("n/a", response.items[0].version);
  81 + Assert.AreEqual("n/a", response.items[0].is_immutable);
  82 + Assert.AreEqual("n/a", response.items[0].permissions);
  83 + Assert.AreEqual("n/a", response.items[0].workflow);
  84 + Assert.AreEqual("n/a", response.items[0].workflow_state);
  85 + Assert.AreEqual("folder", response.items[0].mime_type);
  86 + Assert.AreEqual("folder", response.items[0].mime_icon_path);
  87 + Assert.AreEqual("Folder", response.items[0].mime_display);
  88 + Assert.AreEqual("n/a",response.items[0].storage_path);
  89 + }
  90 + }
  91 +}
... ...
ktwebservice/nunit/document_copy.cs 0 โ†’ 100644
  1 +using NUnit.Framework;
  2 +using System;
  3 +using System.IO;
  4 +
  5 +namespace MonoTests.KnowledgeTree
  6 +{
  7 +
  8 +
  9 + [TestFixture]
  10 + public class DocumentCopyTest : KTTest
  11 + {
  12 + private int _folderId;
  13 + private Document _doc1;
  14 +
  15 +
  16 + [SetUp]
  17 + public void SetUp()
  18 + {
  19 + this._folderId = 1;
  20 +
  21 + this._doc1 = new Document(1, this._session, this._kt, this._verbose, false);
  22 + this._doc1.createFile(this._folderId);
  23 +
  24 +
  25 +
  26 + }
  27 +
  28 + [TearDown]
  29 + public void TearDown()
  30 + {
  31 + this._doc1.deleteFile();
  32 + }
  33 +
  34 + [Test]
  35 + public void FindDocumentBeforeCopy()
  36 + {
  37 + String filename = "Root Folder/test123";
  38 + if (this._verbose) System.Console.WriteLine("Finding document before add: " + filename);
  39 + kt_document_detail documentDetail = this._kt.get_document_detail_by_title(this._session, 1, filename, "");
  40 + if (0 == documentDetail.status_code)
  41 + {
  42 + if (this._verbose) System.Console.WriteLine("Found document - deleting");
  43 + kt_response response = this._kt.delete_document(this._session, documentDetail.document_id, "Delete - cleaning up before add");
  44 + Assert.AreEqual(0, response.status_code);
  45 + }
  46 + else if (this._verbose)
  47 + {
  48 + System.Console.WriteLine("document not found. that is ok!");
  49 + }
  50 + }
  51 +
  52 +
  53 + [Test]
  54 + public void CopyTest()
  55 + {
  56 + kt_document_detail linkresp = this._kt.copy_document(this._session, this._doc1.docId, 1, "copy", "test123", "test123.txt");
  57 + Assert.AreEqual(0, linkresp.status_code);
  58 + Assert.AreEqual("test123.txt", linkresp.filename);
  59 + Assert.AreEqual("test123", linkresp.title);
  60 +
  61 +
  62 +
  63 + }
  64 +
  65 + [Test]
  66 + public void FindDocumentAfterCopy()
  67 + {
  68 + String filename = "Root Folder/test123";
  69 + if (this._verbose) System.Console.WriteLine("Finding document before add: " + filename);
  70 + kt_document_detail documentDetail = this._kt.get_document_detail_by_title(this._session, 1, filename, "");
  71 + Assert.AreEqual(0, documentDetail.status_code);
  72 +
  73 + if (this._verbose) System.Console.WriteLine("Found document - deleting");
  74 + kt_response response = this._kt.delete_document(this._session, documentDetail.document_id, "Delete - cleaning up before add");
  75 + Assert.AreEqual(0, response.status_code);
  76 +
  77 + }
  78 +
  79 +
  80 +
  81 + }
  82 +}
... ...
ktwebservice/nunit/document_detail.cs 0 โ†’ 100644
  1 +using NUnit.Framework;
  2 +using System;
  3 +using System.IO;
  4 +
  5 +namespace MonoTests.KnowledgeTree
  6 +{
  7 + [TestFixture]
  8 + public class DocumentDetailTest : KTTest
  9 + {
  10 + private int _docId;
  11 + private int _folderId;
  12 + private String _filename;
  13 + private String _content;
  14 +
  15 +
  16 + [SetUp]
  17 + public void SetUp()
  18 + {
  19 +
  20 + this._filename = Helper.isUnix()?"/tmp/kt_unit_test1.txt":"c:\\kt_unit_test1.txt";
  21 +
  22 + String filename = "kt unit test1";
  23 +
  24 + this._content = "hello world!";
  25 +
  26 + Helper.writeFile(this._filename, this._content);
  27 + this._folderId = 1;
  28 +
  29 + kt_document_detail response1 = this._kt.add_base64_document(this._session, this._folderId, filename, this._filename, "Default", Helper.ConvertFileToBase64Encoding(this._filename));
  30 +
  31 + if (this._verbose && response1.status_code != 0)
  32 + {
  33 + System.Console.WriteLine("Could not create file: " + this._filename);
  34 + }
  35 + this._docId = response1.document_id;
  36 +
  37 +
  38 + }
  39 +
  40 + [TearDown]
  41 + public void TearDown()
  42 + {
  43 +
  44 + Helper.deleteFile(this._filename);
  45 +
  46 + kt_response response = this._kt.delete_document(this._session, this._docId, "Delete - cleaning up");
  47 + if (this._verbose && response.status_code != 0)
  48 + {
  49 + System.Console.WriteLine("Could not delete file: " + this._filename);
  50 + }
  51 +
  52 + }
  53 +
  54 + [Test]
  55 + public void NonExistantDocumentTest()
  56 + {
  57 + kt_document_detail response = this._kt.get_document_detail(this._session, -1,"");
  58 + Assert.IsFalse(response.status_code == 0);
  59 + }
  60 +
  61 + [Test]
  62 + public void DocumentExistanceTest()
  63 + {
  64 + kt_document_detail response = this._kt.get_document_detail(this._session, this._docId,"MLTVH");
  65 + Assert.AreEqual(0, response.status_code);
  66 + Assert.AreEqual(this._docId, response.document_id);
  67 + Assert.AreEqual("kt unit test1", response.title);
  68 + Assert.AreEqual("n/a", response.custom_document_no);
  69 + Assert.AreEqual("n/a", response.oem_document_no);
  70 + Assert.AreEqual("Default", response.document_type);
  71 + Assert.AreEqual("Root Folder/kt unit test1", response.full_path);
  72 + Assert.AreEqual("kt_unit_test1.txt", response.filename);
  73 + Assert.AreEqual(this._content.Length + 1, response.filesize);
  74 + Assert.AreEqual(this._folderId, response.folder_id);
  75 + Assert.AreEqual("Administrator", response.created_by);
  76 + Assert.IsTrue("" != response.created_date);
  77 + Assert.AreEqual("n/a", response.checked_out_by);
  78 + Assert.IsTrue("" != response.checked_out_date);
  79 + Assert.AreEqual("Administrator", response.modified_by);
  80 + Assert.IsTrue("" != response.modified_date);
  81 + Assert.AreEqual("Administrator", response.owned_by);
  82 + Assert.AreEqual(0.1, response.version);
  83 + Assert.AreEqual(false, response.is_immutable);
  84 + Assert.AreEqual("n/a", response.permissions);
  85 + Assert.AreEqual("n/a", response.workflow);
  86 + Assert.AreEqual("n/a", response.workflow_state);
  87 + Assert.AreEqual("text/plain", response.mime_type);
  88 + Assert.AreEqual("text", response.mime_icon_path);
  89 + Assert.AreEqual("Plain Text", response.mime_display);
  90 + Assert.IsTrue("" != response.storage_path);
  91 + Assert.AreEqual(2, response.metadata.Length);
  92 + Assert.AreEqual(null, response.links);
  93 +
  94 + Assert.AreEqual(1, response.transaction_history.Length);
  95 + Assert.AreEqual("Create", response.transaction_history[0].transaction_name);
  96 + Assert.AreEqual("Administrator", response.transaction_history[0].username);
  97 + Assert.AreEqual(0.1, response.transaction_history[0].version);
  98 + Assert.AreEqual("Document created", response.transaction_history[0].comment);
  99 + Assert.IsTrue("" != response.transaction_history[0].datetime);
  100 +
  101 + Assert.AreEqual(1, response.version_history.Length);
  102 + Assert.AreEqual("Administrator", response.version_history[0].user);
  103 + Assert.AreEqual(0, response.version_history[0].metadata_version);
  104 + Assert.AreEqual(0.1, response.version_history[0].content_version);
  105 +
  106 +
  107 +
  108 + Assert.AreEqual(null, response.transitions);
  109 + }
  110 +
  111 + //[Test]
  112 + public void GetDetailByTitleTest()
  113 + {
  114 + kt_document_detail response = this._kt.get_document_detail_by_name(this._session, 1, "Root Folder/kt unit test1", "T","");
  115 +
  116 + Assert.AreEqual(0, response.status_code);
  117 + Assert.AreEqual(this._docId, response.document_id);
  118 + }
  119 +
  120 +
  121 + //[Test]
  122 + public void GetDetailByTitle2Test()
  123 + {
  124 + kt_document_detail response = this._kt.get_document_detail_by_title(this._session, 1, "Root Folder/kt unit test1", "");
  125 +
  126 + Assert.AreEqual(0, response.status_code);
  127 + Assert.AreEqual(this._docId, response.document_id);
  128 + }
  129 +
  130 + //[Test]
  131 + public void GetDetailByFileTest()
  132 + {
  133 + kt_document_detail response = this._kt.get_document_detail_by_name(this._session, 1, "Root Folder/kt_unit_test1.txt", "F","");
  134 +
  135 + Assert.AreEqual(0, response.status_code);
  136 + Assert.AreEqual(this._docId, response.document_id);
  137 + }
  138 + //[Test]
  139 + public void GetDetailByFile2Test()
  140 + {
  141 + kt_document_detail response = this._kt.get_document_detail_by_filename(this._session, 1, "Root Folder/kt_unit_test1.txt", "");
  142 +
  143 + Assert.AreEqual(0, response.status_code);
  144 + Assert.AreEqual(this._docId, response.document_id);
  145 + }
  146 +
  147 + //[Test]
  148 + public void GetDetailByUnknownNameTest()
  149 + {
  150 + kt_document_detail response = this._kt.get_document_detail_by_name(this._session, 1, "Root Folder/kt_unit_test1.ssssdasdasd", "F","");
  151 + Assert.IsFalse(response.status_code == 0);
  152 + }
  153 + }
  154 +}
... ...
ktwebservice/nunit/document_download.cs 0 โ†’ 100644
  1 +using NUnit.Framework;
  2 +using System;
  3 +using System.IO;
  4 +using System.Net;
  5 +
  6 +namespace MonoTests.KnowledgeTree
  7 +{
  8 + [TestFixture]
  9 + public class DocumentSystemMetadataTest : KTTest
  10 + {
  11 + private int _folderId;
  12 + private Document _doc1;
  13 +
  14 +
  15 + [SetUp]
  16 + public void SetUp()
  17 + {
  18 + this._folderId = 1;
  19 +
  20 + this._doc1 = new Document(1, this._session, this._kt, this._verbose,false);
  21 + this._doc1.createFile(this._folderId);
  22 + }
  23 +
  24 + [TearDown]
  25 + public void TearDown()
  26 + {
  27 + this._doc1.deleteFile();
  28 + }
  29 +
  30 + [Test]
  31 + public void DownloadTest()
  32 + {
  33 + kt_response update_resp = this._kt.download_document(this._session, this._doc1.docId );
  34 + Assert.AreEqual(0, update_resp.status_code);
  35 +
  36 + System.Console.WriteLine("Download...." + update_resp.message);
  37 +
  38 + String uri = update_resp.message;
  39 +
  40 + HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create(uri);
  41 +
  42 + WebResponse response = webrequest.GetResponse();
  43 + StreamReader sr = new StreamReader(response.GetResponseStream());
  44 + String content = sr.ReadToEnd();
  45 +
  46 + System.Console.WriteLine(content);
  47 +
  48 +
  49 + }
  50 +
  51 + [Test]
  52 + public void SmallDownloadTest()
  53 + {
  54 + kt_response update_resp = this._kt.download_small_document(this._session, this._doc1.docId );
  55 + Assert.AreEqual(0, update_resp.status_code);
  56 +
  57 + String filename = Helper.isUnix()?("/tmp/kt_unit_test_tmp.txt"):("c:\\kt_unit_test_tmp.txt");
  58 +
  59 +
  60 +
  61 + long length = Helper.ConvertBase64EncodingToFile(update_resp.message, filename);
  62 + System.Console.WriteLine(Helper.readFile(filename));
  63 +
  64 + // TODO - why???
  65 + Assert.AreEqual(length, this._doc1.filesize+1);
  66 +
  67 + }
  68 + }
  69 +}
... ...
ktwebservice/nunit/document_history.cs 0 โ†’ 100644
  1 +using NUnit.Framework;
  2 +using System;
  3 +using System.IO;
  4 +
  5 +namespace MonoTests.KnowledgeTree
  6 +{
  7 + [TestFixture]
  8 + public class DocumentHistoryTest : KTTest
  9 + {
  10 + private int _folderId;
  11 + private Document _doc1;
  12 +
  13 + [SetUp]
  14 + public void SetUp()
  15 + {
  16 + this._folderId = 1;
  17 +
  18 + this._doc1 = new Document(1, this._session, this._kt, this._verbose,false);
  19 + this._doc1.createFile(this._folderId);
  20 + }
  21 +
  22 + [TearDown]
  23 + public void TearDown()
  24 + {
  25 + this._doc1.deleteFile();
  26 + }
  27 +
  28 + [Test]
  29 + public void ChangeTypeTest()
  30 + {
  31 + kt_document_version_history_response version_resp = this._kt.get_document_version_history(this._session, this._doc1.docId);
  32 + Assert.AreEqual(0, version_resp.status_code);
  33 +
  34 + kt_document_transaction_history_response history_resp = this._kt.get_document_transaction_history(this._session, this._doc1.docId);
  35 + Assert.AreEqual(0, history_resp.status_code);
  36 + }
  37 + }
  38 +}
... ...
ktwebservice/nunit/document_links.cs 0 โ†’ 100644
  1 +using NUnit.Framework;
  2 +using System;
  3 +using System.IO;
  4 +
  5 +namespace MonoTests.KnowledgeTree
  6 +{
  7 +
  8 +
  9 + [TestFixture]
  10 + public class DocumentLinkTest : KTTest
  11 + {
  12 + private int _folderId;
  13 + private Document _doc1;
  14 + private Document _doc2;
  15 +
  16 +
  17 + [SetUp]
  18 + public void SetUp()
  19 + {
  20 + this._folderId = 1;
  21 +
  22 + this._doc1 = new Document(1, this._session, this._kt, this._verbose, false);
  23 + this._doc1.createFile(this._folderId);
  24 + this._doc2 = new Document(2, this._session, this._kt, this._verbose, false);
  25 + this._doc2.createFile(this._folderId);
  26 + }
  27 +
  28 + [TearDown]
  29 + public void TearDown()
  30 + {
  31 + this._doc1.deleteFile();
  32 + this._doc2.deleteFile();
  33 + }
  34 +
  35 + [Test]
  36 + public void LinkingTest()
  37 + {
  38 + kt_linked_document_response linkresp = this._kt.get_document_links(this._session, this._doc1.docId);
  39 + Assert.AreEqual(0, linkresp.status_code);
  40 + Assert.AreEqual(null, linkresp.links);
  41 +
  42 + kt_response response = this._kt.link_documents(this._session, this._doc1.docId, this._doc2.docId, "Reference");
  43 + Assert.AreEqual(0, response.status_code);
  44 +
  45 + linkresp = this._kt.get_document_links(this._session, this._doc1.docId);
  46 + Assert.AreEqual(0, linkresp.status_code);
  47 + Assert.AreEqual(this._doc1.docId, linkresp.parent_document_id);
  48 + Assert.AreEqual(1, linkresp.links.Length);
  49 + Assert.AreEqual(this._doc2.docId, linkresp.links[0].document_id);
  50 + Assert.AreEqual(this._doc2.title, linkresp.links[0].title);
  51 + Assert.AreEqual("Default", linkresp.links[0].document_type);
  52 + Assert.AreEqual(this._doc2.filesize+1, linkresp.links[0].filesize);
  53 + Assert.AreEqual(0.1, linkresp.links[0].version);
  54 + Assert.AreEqual("n/a", linkresp.links[0].workflow);
  55 + Assert.AreEqual("n/a", linkresp.links[0].workflow_state);
  56 + Assert.AreEqual("Reference", linkresp.links[0].link_type);
  57 + Assert.AreEqual("n/a", linkresp.links[0].custom_document_no);
  58 + Assert.AreEqual("n/a", linkresp.links[0].oem_document_no);
  59 +
  60 + response = this._kt.unlink_documents(this._session, this._doc1.docId, this._doc2.docId);
  61 + Assert.AreEqual(0, response.status_code);
  62 +
  63 + linkresp = this._kt.get_document_links(this._session, this._doc1.docId);
  64 + Assert.AreEqual(0, linkresp.status_code);
  65 + Assert.AreEqual(null, linkresp.links);
  66 +
  67 + }
  68 +
  69 +
  70 + }
  71 +}
... ...
ktwebservice/nunit/document_metadata.cs 0 โ†’ 100644
  1 +using NUnit.Framework;
  2 +using System;
  3 +using System.IO;
  4 +
  5 +namespace MonoTests.KnowledgeTree
  6 +{
  7 + [TestFixture]
  8 + public class DocumentMetadataTest : KTTest
  9 + {
  10 + private int _docId;
  11 + private int _folderId;
  12 + private String _filename;
  13 + private String _content;
  14 +
  15 +
  16 + [SetUp]
  17 + public void SetUp()
  18 + {
  19 + this._filename = Helper.isUnix()?"/tmp/kt_unit_test1.txt":"c:\\kt_unit_test1.txt";
  20 +
  21 + String filename = "kt unit test1";
  22 +
  23 + this._content = "hello world!";
  24 +
  25 + Helper.writeFile(this._filename, this._content);
  26 +
  27 + this._folderId = 1;
  28 +
  29 + kt_document_detail response1 = this._kt.add_base64_document(this._session, this._folderId, filename, this._filename, "Default", Helper.ConvertFileToBase64Encoding(this._filename));
  30 +
  31 + if (this._verbose && response1.status_code != 0)
  32 + {
  33 + System.Console.WriteLine("Could not create file: " + this._filename);
  34 + }
  35 + this._docId = response1.document_id;
  36 +
  37 +
  38 + }
  39 +
  40 + [TearDown]
  41 + public void TearDown()
  42 + {
  43 +
  44 + Helper.deleteFile(this._filename);
  45 +
  46 + kt_response response = this._kt.delete_document(this._session, this._docId, "Delete - cleaning up");
  47 + if (this._verbose && response.status_code != 0)
  48 + {
  49 + System.Console.WriteLine("Could not delete file: " + this._filename);
  50 + }
  51 + }
  52 +
  53 + [Test]
  54 + public void GetDocumentTypesTest()
  55 + {
  56 + kt_document_types_response doc_types = this._kt.get_document_types(this._session);
  57 + Assert.AreEqual(0, doc_types.status_code);
  58 + }
  59 +
  60 + [Test]
  61 + public void GetDocumentTypeMetadataTest()
  62 + {
  63 +
  64 + kt_metadata_response metadata = this._kt.get_document_type_metadata(this._session, "Default");
  65 + Assert.AreEqual(0, metadata.status_code);
  66 + }
  67 +
  68 + [Test]
  69 + public void GetDocumentMetadataTest()
  70 + {
  71 +
  72 + kt_metadata_response metadata = this._kt.get_document_metadata(this._session, this._docId);
  73 + Assert.AreEqual(0, metadata.status_code);
  74 + }
  75 +
  76 + [Test]
  77 + public void UpdateDocumentMetadataTest()
  78 + {
  79 + kt_metadata_fieldset[] fs = new kt_metadata_fieldset[1];
  80 + fs[0] = new kt_metadata_fieldset();
  81 + fs[0].fieldset = "General information";
  82 + fs[0].fields = new kt_metadata_field[3];
  83 + fs[0].fields[0] = new kt_metadata_field();
  84 + fs[0].fields[0].name = "Document Author";
  85 + fs[0].fields[0].value = "Joe Soap";
  86 + fs[0].fields[1] = new kt_metadata_field();
  87 + fs[0].fields[1].name = "Category";
  88 + fs[0].fields[1].value = "Technical";
  89 + fs[0].fields[2] = new kt_metadata_field();
  90 + fs[0].fields[2].name = "Media Type";
  91 + fs[0].fields[2].value = "Text";
  92 +
  93 + kt_sysdata_item[] sysdata = new kt_sysdata_item[0];
  94 +
  95 + kt_document_detail update_resp = this._kt.update_document_metadata(this._session, this._docId, fs, sysdata);
  96 + Assert.AreEqual(0, update_resp.status_code);
  97 + Assert.AreEqual("General information", update_resp.metadata[1].fieldset);
  98 +
  99 + Assert.AreEqual("Document Author", update_resp.metadata[1].fields[0].name);
  100 + Assert.AreEqual("Joe Soap", update_resp.metadata[1].fields[0].value);
  101 +
  102 + Assert.AreEqual("Category", update_resp.metadata[1].fields[1].name);
  103 + Assert.AreEqual("Technical", update_resp.metadata[1].fields[1].value);
  104 +
  105 + Assert.AreEqual("Media Type", update_resp.metadata[1].fields[2].name);
  106 + Assert.AreEqual("Text", update_resp.metadata[1].fields[2].value);
  107 +
  108 +
  109 + }
  110 +
  111 + [Test]
  112 + public void UpdateDocumentMetadataWithSpecialCharactersTest()
  113 + {
  114 + kt_metadata_fieldset[] fs = new kt_metadata_fieldset[1];
  115 + fs[0] = new kt_metadata_fieldset();
  116 + fs[0].fieldset = "General information";
  117 + fs[0].fields = new kt_metadata_field[3];
  118 + fs[0].fields[0] = new kt_metadata_field();
  119 + fs[0].fields[0].name = "Document Author";
  120 + fs[0].fields[0].value = "Joe \\Soap";
  121 + fs[0].fields[1] = new kt_metadata_field();
  122 + fs[0].fields[1].name = "Category";
  123 + fs[0].fields[1].value = "Tec/hn\\ical/";
  124 + fs[0].fields[2] = new kt_metadata_field();
  125 + fs[0].fields[2].name = "Media Type";
  126 + fs[0].fields[2].value = "Text'";
  127 +
  128 + kt_sysdata_item[] sysdata = new kt_sysdata_item[0];
  129 +
  130 + kt_document_detail update_resp = this._kt.update_document_metadata(this._session, this._docId, fs, sysdata);
  131 + Assert.AreEqual(0, update_resp.status_code);
  132 + Assert.AreEqual("General information", update_resp.metadata[1].fieldset);
  133 +
  134 + Assert.AreEqual("Document Author", update_resp.metadata[1].fields[0].name);
  135 + Assert.AreEqual("Joe \\Soap", update_resp.metadata[1].fields[0].value);
  136 +
  137 + Assert.AreEqual("Category", update_resp.metadata[1].fields[1].name);
  138 + Assert.AreEqual("Tec/hn\\ical/", update_resp.metadata[1].fields[1].value);
  139 +
  140 + Assert.AreEqual("Media Type", update_resp.metadata[1].fields[2].name);
  141 + Assert.AreEqual("Text'", update_resp.metadata[1].fields[2].value);
  142 +
  143 +
  144 + }
  145 +
  146 +
  147 +
  148 + }
  149 +}
... ...
ktwebservice/nunit/document_owner.cs 0 โ†’ 100644
  1 +using NUnit.Framework;
  2 +using System;
  3 +using System.IO;
  4 +
  5 +namespace MonoTests.KnowledgeTree
  6 +{
  7 + [TestFixture]
  8 + public class DocumentOwnerTest : KTTest
  9 + {
  10 + private int _folderId;
  11 + private Document _doc1;
  12 +
  13 + [SetUp]
  14 + public void SetUp()
  15 + {
  16 + this._folderId = 1;
  17 +
  18 + this._doc1 = new Document(1, this._session, this._kt, this._verbose, false);
  19 + this._doc1.createFile(this._folderId);
  20 + }
  21 +
  22 + [TearDown]
  23 + public void TearDown()
  24 + {
  25 + this._doc1.deleteFile();
  26 + }
  27 +
  28 + [Test]
  29 + public void ChangeOwnerTest()
  30 + {
  31 + kt_document_detail response = this._kt.change_document_owner(this._session, this._doc1.docId, "anonymous", "just trying to change owner");
  32 + Assert.AreEqual(0, response.status_code);
  33 +
  34 + // test to non existant user
  35 + response = this._kt.change_document_owner(this._session, this._doc1.docId, "blah", "just trying to change owner");
  36 + Assert.IsFalse(0 == response.status_code);
  37 + }
  38 + }
  39 +}
... ...
ktwebservice/nunit/document_rename.cs 0 โ†’ 100644
  1 +using NUnit.Framework;
  2 +using System;
  3 +using System.IO;
  4 +
  5 +namespace MonoTests.KnowledgeTree
  6 +{
  7 + [TestFixture]
  8 + public class DocumentRenameTest : KTTest
  9 + {
  10 + private int _folderId;
  11 + private Document _doc1;
  12 +
  13 + [SetUp]
  14 + public void SetUp()
  15 + {
  16 + this._folderId = 1;
  17 +
  18 + this._doc1 = new Document(1, this._session, this._kt, this._verbose,false);
  19 + this._doc1.createFile(this._folderId);
  20 + }
  21 +
  22 + [TearDown]
  23 + public void TearDown()
  24 + {
  25 + this._doc1.deleteFile();
  26 + }
  27 +
  28 + [Test]
  29 + public void RenameTest()
  30 + {
  31 + kt_document_detail response = this._kt.rename_document_filename(this._session, this._doc1.docId, "test fname");
  32 + Assert.AreEqual(0, response.status_code);
  33 + Assert.AreEqual("test fname", response.filename);
  34 +
  35 + response = this._kt.rename_document_title(this._session, this._doc1.docId, "test title");
  36 + Assert.AreEqual(0, response.status_code);
  37 + Assert.AreEqual("test title", response.title);
  38 + }
  39 + }
  40 +}
... ...
ktwebservice/nunit/document_system_metadata.cs 0 โ†’ 100644
  1 +using NUnit.Framework;
  2 +using System;
  3 +using System.IO;
  4 +
  5 +namespace MonoTests.KnowledgeTree
  6 +{
  7 +
  8 +
  9 + [TestFixture]
  10 + public class DocumentSystemMetadataTest : KTTest
  11 + {
  12 + private int _folderId;
  13 + private Document _doc1;
  14 + private Document _doc2;
  15 +
  16 +
  17 + [SetUp]
  18 + public void SetUp()
  19 + {
  20 + this._folderId = 1;
  21 +
  22 +
  23 + this._doc1 = new Document(1, this._session, this._kt, this._verbose,false);
  24 + this._doc1.createFile(this._folderId);
  25 + this._doc2 = new Document(2, this._session, this._kt, this._verbose,true);
  26 + }
  27 +
  28 + [TearDown]
  29 + public void TearDown()
  30 + {
  31 + this._doc1.deleteFile();
  32 + this._doc2.deleteFile();
  33 + }
  34 +
  35 +// [Test]
  36 + public void UpdateDocumentMetadataTest()
  37 + {
  38 +
  39 + kt_metadata_fieldset[] fs = new kt_metadata_fieldset[1];
  40 + fs[0] = new kt_metadata_fieldset();
  41 + fs[0].fieldset = "General information";
  42 + fs[0].fields = new kt_metadata_field[3];
  43 + fs[0].fields[0] = new kt_metadata_field();
  44 + fs[0].fields[0].name = "Document Author";
  45 + fs[0].fields[0].value = "Joe Soap";
  46 + fs[0].fields[1] = new kt_metadata_field();
  47 + fs[0].fields[1].name = "Category";
  48 + fs[0].fields[1].value = "Technical";
  49 + fs[0].fields[2] = new kt_metadata_field();
  50 + fs[0].fields[2].name = "Media Type";
  51 + fs[0].fields[2].value = "Text";
  52 +
  53 + kt_sysdata_item[] sysdata = new kt_sysdata_item[3];
  54 + sysdata[0] = new kt_sysdata_item();
  55 + sysdata[0].name = "created_by";
  56 + sysdata[0].value = "Anonymous";
  57 + sysdata[1] = new kt_sysdata_item();
  58 + sysdata[1].name = "created_date";
  59 + sysdata[1].value = "2007-01-17";
  60 + sysdata[2] = new kt_sysdata_item();
  61 + sysdata[2].name = "modified_by";
  62 + sysdata[2].value = "admin";
  63 +
  64 +
  65 + kt_document_detail update_resp = this._kt.update_document_metadata(this._session, this._doc1.docId, fs, sysdata);
  66 + Assert.AreEqual(0, update_resp.status_code);
  67 + Assert.AreEqual("General information", update_resp.metadata[1].fieldset);
  68 +
  69 + Assert.AreEqual("Document Author", update_resp.metadata[1].fields[0].name);
  70 + Assert.AreEqual("Joe Soap", update_resp.metadata[1].fields[0].value);
  71 +
  72 + Assert.AreEqual("Category", update_resp.metadata[1].fields[1].name);
  73 + Assert.AreEqual("Technical", update_resp.metadata[1].fields[1].value);
  74 +
  75 + Assert.AreEqual("Media Type", update_resp.metadata[1].fields[2].name);
  76 + Assert.AreEqual("Text", update_resp.metadata[1].fields[2].value);
  77 +
  78 + Assert.AreEqual("Anonymous", update_resp.created_by);
  79 + Assert.AreEqual("2007-01-17 00:00:00", update_resp.created_date);
  80 + Assert.AreEqual("Administrator", update_resp.modified_by);
  81 + Assert.AreEqual("2007-01-17 00:00:00", update_resp.created_date);
  82 + }
  83 +
  84 +// [Test]
  85 + public void AddSmallDocumentWithMetadataTest()
  86 + {
  87 + kt_metadata_fieldset[] fs = new kt_metadata_fieldset[1];
  88 + fs[0] = new kt_metadata_fieldset();
  89 + fs[0].fieldset = "General information";
  90 + fs[0].fields = new kt_metadata_field[3];
  91 + fs[0].fields[0] = new kt_metadata_field();
  92 + fs[0].fields[0].name = "Document Author";
  93 + fs[0].fields[0].value = "Joe Soap";
  94 + fs[0].fields[1] = new kt_metadata_field();
  95 + fs[0].fields[1].name = "Category";
  96 + fs[0].fields[1].value = "Technical";
  97 + fs[0].fields[2] = new kt_metadata_field();
  98 + fs[0].fields[2].name = "Media Type";
  99 + fs[0].fields[2].value = "Text";
  100 +
  101 + kt_sysdata_item[] sysdata = new kt_sysdata_item[2];
  102 + sysdata[0] = new kt_sysdata_item();
  103 + sysdata[0].name = "created_by";
  104 + sysdata[0].value = "Anonymous";
  105 + sysdata[1] = new kt_sysdata_item();
  106 + sysdata[1].name = "created_date";
  107 + sysdata[1].value = "2007-01-17";
  108 +
  109 + this._doc2.local=false;
  110 + kt_document_detail update_resp = this._doc2.createFileWithMetadata(this._folderId, fs, sysdata);
  111 +
  112 + Assert.AreEqual(0, update_resp.status_code);
  113 + Assert.AreEqual("General information", update_resp.metadata[1].fieldset);
  114 +
  115 + Assert.AreEqual("Document Author", update_resp.metadata[1].fields[0].name);
  116 + Assert.AreEqual("Joe Soap", update_resp.metadata[1].fields[0].value);
  117 +
  118 + Assert.AreEqual("Category", update_resp.metadata[1].fields[1].name);
  119 + Assert.AreEqual("Technical", update_resp.metadata[1].fields[1].value);
  120 +
  121 + Assert.AreEqual("Media Type", update_resp.metadata[1].fields[2].name);
  122 + Assert.AreEqual("Text", update_resp.metadata[1].fields[2].value);
  123 +
  124 + Assert.AreEqual("Anonymous", update_resp.created_by);
  125 + Assert.AreEqual("2007-01-17 00:00:00", update_resp.created_date);
  126 + }
  127 +
  128 +// [Test]
  129 + public void CheckinSmallDocumentWithMetadataTest()
  130 + {
  131 + kt_metadata_fieldset[] fs = new kt_metadata_fieldset[1];
  132 + fs[0] = new kt_metadata_fieldset();
  133 + fs[0].fieldset = "General information";
  134 + fs[0].fields = new kt_metadata_field[3];
  135 + fs[0].fields[0] = new kt_metadata_field();
  136 + fs[0].fields[0].name = "Document Author";
  137 + fs[0].fields[0].value = "Joe Soap";
  138 + fs[0].fields[1] = new kt_metadata_field();
  139 + fs[0].fields[1].name = "Category";
  140 + fs[0].fields[1].value = "Technical";
  141 + fs[0].fields[2] = new kt_metadata_field();
  142 + fs[0].fields[2].name = "Media Type";
  143 + fs[0].fields[2].value = "Text";
  144 +
  145 + kt_sysdata_item[] sysdata = new kt_sysdata_item[2];
  146 + sysdata[0] = new kt_sysdata_item();
  147 + sysdata[0].name = "created_by";
  148 + sysdata[0].value = "Anonymous";
  149 + sysdata[1] = new kt_sysdata_item();
  150 + sysdata[1].name = "created_date";
  151 + sysdata[1].value = "2007-01-17";
  152 +
  153 + kt_document_detail resp = this._kt.checkout_base64_document(this._session, this._doc1.docId, "test checkin", false);
  154 + Assert.AreEqual(0, resp.status_code);
  155 +
  156 +
  157 +
  158 + kt_document_detail update_resp = this._doc1.checkinFileWithMetadata(this._folderId, fs, sysdata);
  159 +
  160 + Assert.AreEqual(0, update_resp.status_code);
  161 + Assert.AreEqual("General information", update_resp.metadata[1].fieldset);
  162 +
  163 + Assert.AreEqual("Document Author", update_resp.metadata[1].fields[0].name);
  164 + Assert.AreEqual("Joe Soap", update_resp.metadata[1].fields[0].value);
  165 +
  166 + Assert.AreEqual("Category", update_resp.metadata[1].fields[1].name);
  167 + Assert.AreEqual("Technical", update_resp.metadata[1].fields[1].value);
  168 +
  169 + Assert.AreEqual("Media Type", update_resp.metadata[1].fields[2].name);
  170 + Assert.AreEqual("Text", update_resp.metadata[1].fields[2].value);
  171 +
  172 + Assert.AreEqual("Anonymous", update_resp.created_by);
  173 + Assert.AreEqual("2007-01-17 00:00:00", update_resp.created_date);
  174 + }
  175 +
  176 + [Test]
  177 + public void AddDocumentWithMetadataTest()
  178 + {
  179 + kt_metadata_fieldset[] fs = new kt_metadata_fieldset[1];
  180 + fs[0] = new kt_metadata_fieldset();
  181 + fs[0].fieldset = "General information";
  182 + fs[0].fields = new kt_metadata_field[3];
  183 + fs[0].fields[0] = new kt_metadata_field();
  184 + fs[0].fields[0].name = "Document Author";
  185 + fs[0].fields[0].value = "Joe Soap";
  186 + fs[0].fields[1] = new kt_metadata_field();
  187 + fs[0].fields[1].name = "Category";
  188 + fs[0].fields[1].value = "Technical";
  189 + fs[0].fields[2] = new kt_metadata_field();
  190 + fs[0].fields[2].name = "Media Type";
  191 + fs[0].fields[2].value = "Text";
  192 +
  193 + kt_sysdata_item[] sysdata = new kt_sysdata_item[2];
  194 + sysdata[0] = new kt_sysdata_item();
  195 + sysdata[0].name = "created_by";
  196 + sysdata[0].value = "Anonymous";
  197 + sysdata[1] = new kt_sysdata_item();
  198 + sysdata[1].name = "created_date";
  199 + sysdata[1].value = "2007-01-17";
  200 +
  201 +
  202 +
  203 + this._doc2.local = true;
  204 + this._doc2.createFile(this._folderId);
  205 +
  206 +
  207 + FileUploader uploader = new FileUploader( );
  208 +
  209 + uploader.upload(this._session, this._doc2.filename);
  210 +
  211 + System.Console.WriteLine("uploaded: " + uploader.filename);
  212 + kt_document_detail response1 = this._kt.add_document_with_metadata(this._session, this._folderId, this._doc2.title, this._doc2.filename, "Default", uploader.filename,fs, sysdata);
  213 +
  214 + Assert.AreEqual(0, response1.status_code);
  215 + }
  216 +
  217 + [Test]
  218 + public void CheckinDocumentWithMetadataTest()
  219 + {
  220 + kt_metadata_fieldset[] fs = new kt_metadata_fieldset[1];
  221 + fs[0] = new kt_metadata_fieldset();
  222 + fs[0].fieldset = "General information";
  223 + fs[0].fields = new kt_metadata_field[3];
  224 + fs[0].fields[0] = new kt_metadata_field();
  225 + fs[0].fields[0].name = "Document Author";
  226 + fs[0].fields[0].value = "Joe Soap";
  227 + fs[0].fields[1] = new kt_metadata_field();
  228 + fs[0].fields[1].name = "Category";
  229 + fs[0].fields[1].value = "Technical";
  230 + fs[0].fields[2] = new kt_metadata_field();
  231 + fs[0].fields[2].name = "Media Type";
  232 + fs[0].fields[2].value = "Text";
  233 +
  234 + kt_sysdata_item[] sysdata = new kt_sysdata_item[2];
  235 + sysdata[0] = new kt_sysdata_item();
  236 + sysdata[0].name = "created_by";
  237 + sysdata[0].value = "Anonymous";
  238 + sysdata[1] = new kt_sysdata_item();
  239 + sysdata[1].name = "created_date";
  240 + sysdata[1].value = "2007-01-17";
  241 +
  242 + kt_document_detail resp = this._kt.checkout_base64_document(this._session, this._doc1.docId, "test checkin", false);
  243 + Assert.AreEqual(0, resp.status_code);
  244 +
  245 + FileUploader uploader = new FileUploader( );
  246 +
  247 + uploader.upload(this._session, this._doc1.filename);
  248 +
  249 + kt_document_detail update_resp = this._kt.checkin_document(this._session, this._doc1.docId, this._doc1.filename, "unit test - doing checkin", uploader.filename, false);
  250 + Assert.AreEqual(0, update_resp.status_code);
  251 + }
  252 +
  253 + }
  254 +}
... ...
ktwebservice/nunit/document_type.cs 0 โ†’ 100644
  1 +using NUnit.Framework;
  2 +using System;
  3 +using System.IO;
  4 +
  5 +namespace MonoTests.KnowledgeTree
  6 +{
  7 + [TestFixture]
  8 + public class DocumentOwnerTest : KTTest
  9 + {
  10 + private int _folderId;
  11 + private Document _doc1;
  12 +
  13 + [SetUp]
  14 + public void SetUp()
  15 + {
  16 + this._folderId = 1;
  17 +
  18 +
  19 + this._doc1 = new Document(1, this._session, this._kt, this._verbose,false);
  20 + this._doc1.createFile(this._folderId);
  21 +
  22 + this._verbose = true;
  23 +
  24 + }
  25 +
  26 + [TearDown]
  27 + public void TearDown()
  28 + {
  29 + this._doc1.deleteFile();
  30 + }
  31 +
  32 + [Test]
  33 + public void ChangeTypeTest()
  34 + {
  35 + // NOTE: Create the following type 'NewType' via the admin pages
  36 +
  37 + kt_document_detail response = this._kt.change_document_type(this._session, this._doc1.docId, "NewType");
  38 + Assert.AreEqual(0, response.status_code);
  39 + if (0 != response.status_code)
  40 + {
  41 + System.Console.WriteLine("Please check that the document type 'NewType' exists in the database! This test should pass if it exists!");
  42 + System.Console.WriteLine("SQL: insert into document_types_lookup(name) values('NewType');");
  43 + }
  44 +
  45 + // NOTE: we need to test with an unknown type as well
  46 +
  47 + response = this._kt.change_document_type(this._session, this._doc1.docId, "UnknownType");
  48 + Assert.IsTrue(0 != response.status_code);
  49 +
  50 + }
  51 + }
  52 +}
... ...
ktwebservice/nunit/document_workflow.cs 0 โ†’ 100644
  1 +using NUnit.Framework;
  2 +using System;
  3 +using System.IO;
  4 +
  5 +namespace MonoTests.KnowledgeTree
  6 +{
  7 + [TestFixture]
  8 + public class WorkflowTest : KTTest
  9 + {
  10 + private int _folderId;
  11 + private Document _doc1;
  12 +
  13 + [SetUp]
  14 + public void SetUp()
  15 + {
  16 + this._folderId = 1;
  17 +
  18 + this._doc1 = new Document(1, this._session, this._kt, this._verbose, false);
  19 + this._doc1.createFile(this._folderId);
  20 + }
  21 +
  22 + [TearDown]
  23 + public void TearDown()
  24 + {
  25 + this._doc1.deleteFile();
  26 + }
  27 +
  28 + [Test]
  29 + public void NonExistantWorkflowTest()
  30 + {
  31 + kt_document_detail response = this._kt.start_document_workflow(this._session, this._doc1.docId, "Non Existant Workflow");
  32 + Assert.IsTrue(0 != response.status_code);
  33 + }
  34 +
  35 + [Test]
  36 + public void StartWorkflowTest()
  37 + {
  38 + kt_document_detail response = this._kt.start_document_workflow(this._session, this._doc1.docId, "Review Process");
  39 + Assert.AreEqual(0, response.status_code);
  40 + Assert.AreEqual("Review Process", response.workflow);
  41 + }
  42 +
  43 + [Test]
  44 + public void StopWorkflowTest()
  45 + {
  46 + kt_document_detail response = this._kt.start_document_workflow(this._session, this._doc1.docId, "Review Process");
  47 + Assert.AreEqual(0, response.status_code);
  48 + Assert.AreEqual("Review Process", response.workflow);
  49 +
  50 + response = this._kt.delete_document_workflow(this._session, this._doc1.docId);
  51 + Assert.AreEqual(0, response.status_code);
  52 + Assert.AreEqual("n/a", response.workflow);
  53 + }
  54 +
  55 + [Test]
  56 + public void GetTransitionsTest()
  57 + {
  58 + kt_document_detail response = this._kt.start_document_workflow(this._session, this._doc1.docId, "Review Process");
  59 + Assert.AreEqual(0, response.status_code);
  60 + Assert.AreEqual("Review Process", response.workflow);
  61 +
  62 + kt_workflow_transitions_response trans_resp = this._kt.get_document_workflow_transitions(this._session, this._doc1.docId);
  63 + Assert.AreEqual(0, trans_resp.status_code);
  64 + Assert.AreEqual(1, trans_resp.transitions.Length);
  65 + Assert.AreEqual("Request Approval", trans_resp.transitions[0]);
  66 + }
  67 +
  68 + [Test]
  69 + public void WorkflowTransitionTest()
  70 + {
  71 + kt_document_detail response = this._kt.start_document_workflow(this._session, this._doc1.docId, "Review Process");
  72 + Assert.AreEqual(0, response.status_code);
  73 + Assert.AreEqual("Review Process", response.workflow);
  74 + Assert.AreEqual("Draft", response.workflow_state);
  75 +
  76 + response = this._kt.perform_document_workflow_transition(this._session, this._doc1.docId, "Request Approval", "Please approve me");
  77 + Assert.AreEqual(0, response.status_code);
  78 + Assert.AreEqual("Review Process", response.workflow);
  79 + Assert.AreEqual("Approval", response.workflow_state);
  80 +
  81 + response = this._kt.perform_document_workflow_transition(this._session, this._doc1.docId, "Approve", "Ok!");
  82 + Assert.AreEqual(0, response.status_code);
  83 + Assert.AreEqual("Review Process", response.workflow);
  84 + Assert.AreEqual("Published", response.workflow_state);
  85 + }
  86 + }
  87 +}
... ...
ktwebservice/nunit/folder.cs 0 โ†’ 100644
  1 +using NUnit.Framework;
  2 +using System;
  3 +using System.IO;
  4 +
  5 +namespace MonoTests.KnowledgeTree
  6 +{
  7 + [TestFixture]
  8 + public class FolderTest : KTTest
  9 + {
  10 +
  11 + private int _folder_id;
  12 + private int _subfolder_id;
  13 +
  14 + [SetUp]
  15 + public void SetUp()
  16 + {
  17 + }
  18 +
  19 + [TearDown]
  20 + public void TearDown()
  21 + {
  22 + }
  23 +
  24 + [Test]
  25 + public void GetFolderDetail()
  26 + {
  27 +
  28 + kt_folder_detail response = this._kt.get_folder_detail(this._session, 1);
  29 + Assert.AreEqual(0, response.status_code);
  30 + Assert.AreEqual(1, response.id);
  31 + Assert.AreEqual("Root Folder", response.folder_name);
  32 + Assert.AreEqual(0, response.parent_id);
  33 + Assert.AreEqual("Root Folder", response.full_path);
  34 + }
  35 +
  36 + [Test]
  37 + public void AddFolder()
  38 + {
  39 +
  40 + kt_folder_detail response = this._kt.create_folder(this._session, 1, "kt_unit_test");
  41 + Assert.AreEqual(0,response.status_code);
  42 +
  43 + this._folder_id = response.id;
  44 +
  45 + response = this._kt.create_folder(this._session, this._folder_id, "subfolder");
  46 + Assert.AreEqual(0,response.status_code);
  47 +
  48 + this._subfolder_id = response.id;
  49 +
  50 + }
  51 +
  52 + [Test]
  53 + public void GetFolderByName()
  54 + {
  55 +
  56 + kt_folder_detail response = this._kt.get_folder_detail_by_name(this._session, "/kt_unit_test");
  57 + Assert.AreEqual(0,response.status_code);
  58 + Assert.AreEqual(this._folder_id, response.id);
  59 +
  60 + response = this._kt.get_folder_detail_by_name(this._session, "kt_unit_test");
  61 + Assert.AreEqual(0,response.status_code);
  62 + Assert.AreEqual(this._folder_id, response.id);
  63 +
  64 + response = this._kt.get_folder_detail_by_name(this._session, "kt_unit_test/subfolder");
  65 + Assert.AreEqual(0,response.status_code);
  66 + Assert.AreEqual(this._subfolder_id,response.id);
  67 +
  68 + response = this._kt.get_folder_detail_by_name(this._session, "kt_unit_test/subfolder2");
  69 + Assert.IsFalse(response.status_code == 0);
  70 +
  71 +
  72 + }
  73 +
  74 + [Test]
  75 + public void GetFolderContents()
  76 + {
  77 + kt_folder_contents response = this._kt.get_folder_contents(this._session, this._folder_id, 1, "DF");
  78 + Assert.AreEqual(0,response.status_code);
  79 + Assert.AreEqual(this._folder_id,response.folder_id);
  80 + Assert.AreEqual("kt_unit_test", response.folder_name);
  81 + Assert.AreEqual("Root Folder/kt_unit_test", response.full_path);
  82 +
  83 + kt_folder_contents response2 = this._kt.get_folder_contents(this._session, this._subfolder_id, 1, "DF");
  84 + Assert.AreEqual(0, response2.status_code);
  85 + Assert.AreEqual(this._subfolder_id, response2.folder_id);
  86 + Assert.AreEqual("subfolder", response2.folder_name);
  87 + Assert.AreEqual("Root Folder/kt_unit_test/subfolder", response2.full_path);
  88 + }
  89 +
  90 + [Test]
  91 + public void RenameFolder()
  92 + {
  93 + kt_response response = this._kt.rename_folder(this._session, this._subfolder_id, "subfolde'r2");
  94 + Assert.AreEqual(0, response.status_code);
  95 +
  96 + kt_folder_detail response2 = this._kt.get_folder_detail(this._session, this._subfolder_id);
  97 + Assert.AreEqual(0, response2.status_code);
  98 + Assert.AreEqual(this._subfolder_id, response2.id);
  99 + Assert.AreEqual("subfolde'r2", response2.folder_name);
  100 + Assert.AreEqual(this._folder_id, response2.parent_id);
  101 + Assert.AreEqual("Root Folder/kt_unit_test/subfolde'r2", response2.full_path);
  102 + }
  103 +
  104 + [Test]
  105 + public void RemoveFolder()
  106 + {
  107 + kt_response response = this._kt.delete_folder(this._session, this._folder_id, "unit testing remove");
  108 + Assert.AreEqual(0, response.status_code);
  109 + }
  110 +
  111 + [Test]
  112 + public void AddFolderWithSpecialCharacters()
  113 + {
  114 + kt_folder_detail response = this._kt.create_folder(this._session, 1, "kt.unit.test");
  115 + Assert.AreEqual(0,response.status_code);
  116 + Assert.AreEqual("kt.unit.test",response.folder_name);
  117 +
  118 + response = this._kt.create_folder(this._session, 1, "kt ' unit \" test");
  119 + Assert.AreEqual(0,response.status_code);
  120 + Assert.AreEqual("kt ' unit \" test",response.folder_name);
  121 +
  122 + response = this._kt.create_folder(this._session, 1, "kt - unit - test");
  123 + Assert.AreEqual(0,response.status_code);
  124 + Assert.AreEqual("kt - unit - test",response.folder_name);
  125 + }
  126 + }
  127 +}
... ...
ktwebservice/nunit/helper.cs 0 โ†’ 100644
  1 +using System;
  2 +using System.Text;
  3 +using System.Net;
  4 +using System.IO;
  5 +using System.Collections;
  6 +using System.Data;
  7 +using System.Data.Odbc;
  8 +
  9 +namespace MonoTests.KnowledgeTree
  10 +{
  11 +
  12 +
  13 +
  14 + [System.Web.Services.WebServiceBinding(Name="KnowledgeTreePort", Namespace="urn:KnowledgeTree")]
  15 + public class KTWebService : KnowledgeTreeService
  16 + {
  17 + public KTWebService() : base()
  18 + {
  19 + this.Url = Environment.GetEnvironmentVariable("KT_ROOT_URL") + "/ktwebservice/webservice.php";
  20 + }
  21 + }
  22 +
  23 + public class KTTest
  24 + {
  25 + protected KTWebService _kt;
  26 + protected String _session;
  27 + protected bool _verbose;
  28 +
  29 +
  30 + public KTTest()
  31 + {
  32 + this._kt = new KTWebService();
  33 + kt_response response = this._kt.login("admin","admin","127.0.0.1");
  34 + this._session = response.message;
  35 + this._verbose = false;
  36 + this.setupDb();
  37 + }
  38 +
  39 + void setupDb()
  40 + {
  41 +
  42 + String connectionString = "DSN=ktdms;" + "UID=root;" + "PWD=";
  43 + try
  44 + {
  45 + IDbConnection dbcon = new OdbcConnection(connectionString);
  46 + if (dbcon == null)
  47 + {
  48 + System.Console.WriteLine("Cannot create connection");
  49 + }
  50 + dbcon.Open();
  51 + IDbCommand dbcmd = dbcon.CreateCommand();
  52 + if (dbcmd == null)
  53 + {
  54 + System.Console.WriteLine("Cannot create command");
  55 + }
  56 + dbcmd.CommandText = "DELETE FROM folders WHERE id > 1";
  57 + dbcmd.CommandType = CommandType.Text;
  58 + dbcmd.ExecuteNonQuery();
  59 + dbcmd.CommandText = "DELETE FROM documents";
  60 + dbcmd.CommandType = CommandType.Text;
  61 + dbcmd.ExecuteNonQuery();
  62 + dbcmd.CommandText = "DELETE FROM document_types_lookup WHERE name = 'NewType'";
  63 + dbcmd.ExecuteNonQuery();
  64 + dbcmd.CommandText = "INSERT INTO document_types_lookup(id,name) VALUES(2,'NewType')";
  65 + dbcmd.ExecuteNonQuery();
  66 + dbcmd.Dispose();
  67 + dbcmd = null;
  68 + dbcon.Close();
  69 + dbcon = null;
  70 + }
  71 + catch(Exception ex)
  72 + {
  73 + System.Console.WriteLine(ex.Message);
  74 + }
  75 + }
  76 +
  77 + ~KTTest()
  78 + {
  79 + this._kt.logout(this._session);
  80 + }
  81 + }
  82 +
  83 +
  84 +
  85 + public class FileUploader
  86 + {
  87 + private String boundary;
  88 + private String uri;
  89 + public String filename;
  90 +
  91 +
  92 + public FileUploader(String uri)
  93 + {
  94 + this.uri = uri;
  95 + System.Console.WriteLine("Using upload URL: " + uri);
  96 + this.boundary = "----" + DateTime.Now.Ticks.ToString("x");
  97 + }
  98 +
  99 + public FileUploader() : this(Environment.GetEnvironmentVariable("KT_ROOT_URL") + "/ktwebservice/upload.php")
  100 + {
  101 + }
  102 +
  103 +
  104 + public String getFilename()
  105 + {
  106 + return this.filename;
  107 + }
  108 +
  109 +
  110 + public void upload(String sessionid, String filename)
  111 + {
  112 + String displayname = Path.GetFileName(filename);
  113 + StringBuilder header = new StringBuilder();
  114 +
  115 + header.Append("--" + boundary + "\r\n" + "Content-Disposition: form-data; name=\"session_id\"\r\n\r\n" + sessionid + "\r\n");
  116 + header.Append("--" + boundary + "\r\n" + "Content-Disposition: form-data; name=\"action\"\r\n\r\nA\r\n");
  117 + header.Append("--" + boundary + "\r\n" + "Content-Disposition: form-data; name=\"output\"\r\n\r\nxml\r\n");
  118 +
  119 + header.Append("--" + boundary + "\r\n");
  120 + header.Append("Content-Disposition: form-data; name=\"name\";");
  121 + header.Append("filename=\"" + displayname + "\"\r\nContent-Type: application/octet-stream\r\n\r\n");
  122 +
  123 +
  124 + HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create(this.uri);
  125 + webrequest.ContentType = "multipart/form-data; boundary=" + boundary;
  126 + webrequest.Method = "POST";
  127 +
  128 +
  129 + byte[] headerArray = Encoding.UTF8.GetBytes(header.ToString());
  130 + byte[] boundaryArray = Encoding.ASCII.GetBytes("\r\n--" + boundary + "\r\n");
  131 +
  132 + FileStream file = new FileStream(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read);
  133 +
  134 + long filesize = file.Length;
  135 + webrequest.ContentLength = headerArray.Length + filesize + boundaryArray.Length;
  136 +
  137 + Stream requestStream = webrequest.GetRequestStream();
  138 + requestStream.Write(headerArray, 0, headerArray.Length);
  139 +
  140 + byte[] buffer = new byte[10240];
  141 +
  142 + int read = 0;
  143 +
  144 + while ((read = file.Read(buffer, 0, buffer.Length)) > 0)
  145 + {
  146 +
  147 + requestStream.Write(buffer, 0, read);
  148 + }
  149 +
  150 + requestStream.Write(boundaryArray, 0, boundaryArray.Length);
  151 +
  152 +
  153 + WebResponse response = webrequest.GetResponse();
  154 + StreamReader sr = new StreamReader(response.GetResponseStream());
  155 + String xml = sr.ReadToEnd();
  156 + //System.Console.WriteLine("xml: " + xml);
  157 +
  158 +
  159 +
  160 + if (xml.IndexOf("<status_code>0</status_code>") != -1)
  161 + {
  162 + long tmp = this.tokenInt("filesize",xml);
  163 + if (tmp != filesize)
  164 + {
  165 + throw new Exception("Filesize should be " + filesize + " but appears to be "+ tmp);
  166 + }
  167 +
  168 + tmp = this.tokenInt("error",xml);
  169 + if (tmp > 0)
  170 + {
  171 + throw new Exception("The server reported error code " + tmp + " for the file upload");
  172 + }
  173 + this.filename = this.tokenString("filename",xml);
  174 + // yay, all is good!
  175 + return;
  176 + }
  177 +
  178 + String msg = this.tokenString("msg", xml);
  179 + long error = this.tokenInt("error", xml);
  180 + if (error > 0)
  181 + {
  182 + throw new Exception("The server reported error code " + error + " for the file upload");
  183 + }
  184 +
  185 + throw new Exception("Upload error: " + msg);
  186 +
  187 + }
  188 +
  189 + private String tokenString(String token, String xml)
  190 + {
  191 + int tokStart = xml.IndexOf("<"+token+">") + token.Length+2;
  192 + int tokEnd = xml.IndexOf("</"+token+">");
  193 + if (tokEnd == -1) return "";
  194 +
  195 + String value = xml.Substring(tokStart, tokEnd-tokStart);
  196 + //System.Console.WriteLine(token + ": " + value);
  197 + return value;
  198 + }
  199 +
  200 + private long tokenInt(String token, String xml)
  201 + {
  202 + String value = this.tokenString(token, xml);
  203 + if (value.Equals(""))
  204 + {
  205 + return -1;
  206 + }
  207 + return long.Parse(value);
  208 + }
  209 +
  210 + }
  211 +
  212 +
  213 +
  214 + public class Document
  215 + {
  216 + public String title;
  217 + public String filename;
  218 + public String realFilename;
  219 + public String content;
  220 + public int docId;
  221 + public String session;
  222 + public KnowledgeTreeService kt;
  223 + public long filesize;
  224 + public bool verbose;
  225 + public bool local;
  226 +
  227 + public Document(int offset, String session, KnowledgeTreeService kt, bool verbose, bool local)
  228 + {
  229 + this.title = "kt unit test" + offset;
  230 + this.realFilename = "kt_unit_test" + offset + ".txt";
  231 + this.filename = (Helper.isUnix()?("/tmp/"):("c:\\")) + this.realFilename;
  232 + this.content = "Hello World!\nThis is a test! And more!\n\n\r\n";
  233 + this.docId = 0;
  234 + this.session = session;
  235 + this.kt = kt;
  236 + this.verbose =verbose;
  237 + this.local = local;
  238 + }
  239 +
  240 + public kt_document_detail createFile(int folderId)
  241 + {
  242 + Helper.writeFile(this.filename, this.content);
  243 + this.filesize = this.content.Length;
  244 +
  245 + if (this.local)
  246 + {
  247 + return null;
  248 + }
  249 + kt_document_detail d1 = this.kt.get_document_detail_by_title(this.session, folderId, this.title, "");
  250 + if (d1.status_code == 1)
  251 + {
  252 + this.docId = d1.document_id;
  253 + this.deleteFile();
  254 + }
  255 +
  256 + kt_document_detail response1 = this.kt.add_base64_document(this.session, folderId, this.title, this.filename, "Default", Helper.ConvertFileToBase64Encoding(this.filename));
  257 +
  258 + if (response1.status_code == 0)
  259 + {
  260 + this.docId = response1.document_id;
  261 + }
  262 +
  263 + if (this.verbose)
  264 + {
  265 + if (response1.status_code == 0)
  266 + {
  267 + System.Console.WriteLine("docid: " + this.docId + " filename: " + this.filename);
  268 + }
  269 + else
  270 + {
  271 + System.Console.WriteLine("Could not create file: " + this.filename);
  272 + }
  273 + }
  274 +
  275 + return response1;
  276 +
  277 + }
  278 +
  279 + public kt_document_detail createFileWithMetadata(int folderId, kt_metadata_fieldset[] metadata, kt_sysdata_item[] sysdata)
  280 + {
  281 + Helper.writeFile(this.filename, this.content);
  282 +
  283 + this.filesize = this.content.Length;
  284 +
  285 + if (this.local)
  286 + {
  287 + return null;
  288 + }
  289 +
  290 + kt_document_detail d1 = this.kt.get_document_detail_by_title(this.session, folderId, this.title, "");
  291 + if (d1.status_code == 1)
  292 + {
  293 + this.docId = d1.document_id;
  294 + this.deleteFile();
  295 + }
  296 +
  297 + kt_document_detail response1 = this.kt.add_base64_document_with_metadata(this.session, folderId, this.title, this.filename, "Default", Helper.ConvertFileToBase64Encoding(this.filename), metadata, sysdata);
  298 +
  299 + if (response1.status_code == 0)
  300 + {
  301 + this.docId = response1.document_id;
  302 + }
  303 +
  304 + if (this.verbose)
  305 + {
  306 + if (response1.status_code == 0)
  307 + {
  308 + System.Console.WriteLine("docid: " + this.docId + " filename: " + this.filename);
  309 + }
  310 + else
  311 + {
  312 + System.Console.WriteLine("Could not create file: " + this.filename);
  313 + }
  314 + }
  315 +
  316 + return response1;
  317 + }
  318 +
  319 + public kt_document_detail checkinFileWithMetadata(int folderId, kt_metadata_fieldset[] metadata, kt_sysdata_item[] sysdata)
  320 + {
  321 + Helper.writeFile(this.filename, this.content);
  322 + this.filesize = this.content.Length;
  323 +
  324 + if (this.local)
  325 + {
  326 + return null;
  327 + }
  328 +
  329 + kt_document_detail d1 = this.kt.get_document_detail_by_title(this.session, folderId, this.title, "");
  330 + if (d1.status_code == 1)
  331 + {
  332 + this.docId = d1.document_id;
  333 + this.deleteFile();
  334 + }
  335 +
  336 + kt_document_detail response1 = this.kt.checkin_base64_document_with_metadata(this.session, this.docId, this.filename, "checkin reason", Helper.ConvertFileToBase64Encoding(this.filename), false, metadata, sysdata);
  337 +
  338 + if (response1.status_code == 0)
  339 + {
  340 + this.docId = response1.document_id;
  341 + }
  342 +
  343 + if (this.verbose)
  344 + {
  345 + if (response1.status_code == 0)
  346 + {
  347 + System.Console.WriteLine("docid: " + this.docId + " filename: " + this.filename);
  348 + }
  349 + else
  350 + {
  351 + System.Console.WriteLine("Could not create file: " + this.filename);
  352 + }
  353 + }
  354 +
  355 + return response1;
  356 + }
  357 +
  358 +
  359 +
  360 + public void deleteFile()
  361 + {
  362 + Helper.deleteFile(this.filename);
  363 +
  364 + if (this.local)
  365 + {
  366 + return;
  367 + }
  368 +
  369 + if (this.docId > 0)
  370 + {
  371 +
  372 + kt_response response = this.kt.delete_document(this.session, this.docId, "Delete - cleaning up");
  373 + if (this.verbose && response.status_code != 0)
  374 + {
  375 + System.Console.WriteLine("Could not delete file: " + this.filename);
  376 + }
  377 + }
  378 + }
  379 + }
  380 +
  381 +
  382 + public class Helper
  383 + {
  384 + public static bool isUnix()
  385 + {
  386 + // found reference on: http://www.mono-project.com/FAQ:_Technical
  387 + int platform = (int) Environment.OSVersion.Platform;
  388 + return (platform == 4) || (platform == 128);
  389 + }
  390 +
  391 + public static void writeFile(String filename, String text)
  392 + {
  393 + try
  394 + {
  395 + TextWriter tw = new StreamWriter(filename);
  396 + tw.WriteLine(text );
  397 + tw.Close();
  398 + }
  399 + catch (System.Exception exp)
  400 + {
  401 + System.Console.WriteLine("{0}", exp.Message);
  402 + throw;
  403 + }
  404 + }
  405 +
  406 + public static String readFile(String filename)
  407 + {
  408 + String text = null;
  409 + try
  410 + {
  411 + FileStream inFile = new FileStream(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read);
  412 + StreamReader sr = new StreamReader(inFile);
  413 + text = sr.ReadToEnd();
  414 + inFile.Close();
  415 + }
  416 + catch (System.Exception exp)
  417 + {
  418 + System.Console.WriteLine("{0}", exp.Message);
  419 + throw;
  420 + }
  421 +
  422 + return text;
  423 + }
  424 +
  425 + public static void deleteFile(string filename)
  426 + {
  427 + try
  428 + {
  429 + File.Delete(filename);
  430 + }
  431 + catch(System.Exception)
  432 + {
  433 + // we are using this to cleanup, so don't handle
  434 + }
  435 + }
  436 +
  437 + public static string ConvertFileToBase64Encoding(string filename)
  438 + {
  439 + System.IO.FileStream inFile;
  440 +
  441 + byte[] binaryData;
  442 + string base64String = "";
  443 +
  444 + try
  445 + {
  446 + inFile = new System.IO.FileStream(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read);
  447 + binaryData = new Byte[inFile.Length];
  448 + inFile.Read(binaryData, 0, (int)inFile.Length);
  449 + inFile.Close();
  450 +
  451 + base64String = System.Convert.ToBase64String(binaryData, 0, binaryData.Length);
  452 + }
  453 + catch (System.Exception exp)
  454 + {
  455 + System.Console.WriteLine("{0}", exp.Message);
  456 + throw;
  457 + }
  458 +
  459 + return base64String;
  460 + }
  461 +
  462 + public static long ConvertBase64EncodingToFile(String encoding, string filename)
  463 + {
  464 + System.IO.FileStream inFile;
  465 +
  466 + byte[] binaryData;
  467 +
  468 + try
  469 + {
  470 + binaryData = Convert.FromBase64String (encoding);
  471 +
  472 + inFile = new System.IO.FileStream(filename, System.IO.FileMode.Create);
  473 +
  474 + inFile.Write(binaryData, 0, (int)binaryData.Length);
  475 + inFile.Close();
  476 + }
  477 + catch (System.Exception exp)
  478 + {
  479 + System.Console.WriteLine("{0}", exp.Message);
  480 + throw;
  481 + }
  482 + return binaryData.Length;
  483 + }
  484 +
  485 + }
  486 +}
... ...
ktwebservice/nunit/inventory.txt 0 โ†’ 100644
  1 +authentication.cs
  2 +=================
  3 +*login
  4 +*logout
  5 +
  6 +document_add.cs
  7 +===============
  8 +
  9 +*add_base64_document
  10 +*delete_document
  11 +*delete_folder
  12 +*get_document_detail_by_name
  13 +*get_folder_detail_by_name
  14 +
  15 +document_checkout.cs
  16 +====================
  17 +
  18 +*checkin_base64_document
  19 +*checkout_base64_document
  20 +*undo_document_checkout
  21 +
  22 +document_detail.cs
  23 +==================
  24 +
  25 +*get_document_detail
  26 +*get_document_detail_by_name
  27 +
  28 +document_links.cs
  29 +=================
  30 +
  31 +*get_document_links
  32 +*link_documents
  33 +*unlink_documents
  34 +
  35 +document_owner.cs
  36 +=================
  37 +
  38 +*change_document_owner
  39 +
  40 +
  41 +document_type.cs
  42 +================
  43 +
  44 +*change_document_type
  45 +
  46 +document_history.cs
  47 +===================
  48 +
  49 +*get_document_version_history
  50 +*get_document_transaction_history
  51 +
  52 +document_rename.cs
  53 +==================
  54 +
  55 +*rename_document_filename
  56 +*rename_document_title
  57 +
  58 +document_workflow.cs
  59 +====================
  60 +
  61 +*start_document_workflow
  62 +*stop_document_workflow
  63 +*perform_document_workflow_transition
  64 +*get_document_workflow_transitions
  65 +
  66 +document_metadata.cs
  67 +====================
  68 +
  69 +*get_document_types
  70 +*get_document_type_metadata
  71 +*get_document_metadata
  72 +*update_document_metadata
  73 +
  74 +folder.cs
  75 +=========
  76 +
  77 +*get_folder_detail
  78 +*create_folder
  79 +*get_folder_detail_by_name
  80 +*get_folder_contents
  81 +*delete_folder
  82 +
  83 +document_system_metadata.cs
  84 +===========================
  85 +
  86 +*update_document_metadata
... ...
ktwebservice/nunit/makefile 0 โ†’ 100644
  1 +RESULTS= authentication.result document_detail.result document_contents.result document_history.result folder.result document_metadata.result document_add.result document_checkout.result document_type.result document_links.result document_owner.result document_rename.result document_workflow.result document_copy.result document_system_metadata.result document_download.result
  2 +PROXY=KTproxy.cs
  3 +WSDL=ktdms.wsdl
  4 +ROOT_URL=http://ktdms.trunk
  5 +WSDL_URL=${ROOT_URL}/ktwebservice/index.php?wsdl
  6 +
  7 +all: ${RESULTS}
  8 +
  9 +results: clean-results ${RESULTS}
  10 +
  11 +KTproxy.dll: KTproxy.cs helper.cs
  12 + mcs -r:System.Web.Services -r:System.Data.dll /target:library KTproxy.cs helper.cs
  13 +
  14 +KTproxy.cs: ktdms.wsdl
  15 + wsdl -out:${PROXY} ${WSDL}
  16 +
  17 +ktdms.wsdl:
  18 + curl ${WSDL_URL} > ${WSDL}
  19 +
  20 +clean:
  21 + rm -f *.dll *.exe ${WSDL} ${PROXY} TestResult.xml *.dll.mdb *.result
  22 +
  23 +clean-results:
  24 + rm -f ${RESULTS}
  25 +
  26 +%.dll: %.cs KTproxy.dll
  27 + mcs -r:System.Web.Services -r:nunit.framework /r:KTproxy.dll -debug /target:library -out:$@ $<
  28 +
  29 +%.result: %.dll
  30 + (export KT_ROOT_URL=${ROOT_URL}; nunit-console $<)
  31 + mv TestResult.xml $@
... ...
ktwebservice/nunit/query.cs 0 โ†’ 100644
  1 +using NUnit.Framework;
  2 +using System;
  3 +using System.IO;
  4 +
  5 +namespace MonoTests.KnowledgeTree
  6 +{
  7 + [TestFixture]
  8 + public class QueryTest : KTTest
  9 + {
  10 +
  11 +
  12 + [SetUp]
  13 + public void SetUp()
  14 + {
  15 + }
  16 +
  17 + [TearDown]
  18 + public void TearDown()
  19 + {
  20 + }
  21 +
  22 + [Test]
  23 + public void Query()
  24 + {
  25 + Document doc = new Document(0,this._session, this._kt, false, false);
  26 + doc.createFile(1);
  27 + int filesize = doc.content.Length+1;
  28 + kt_search_response response = this._kt.search(this._session, "Filesize = \""+filesize+"\"", "");
  29 +
  30 + Assert.AreEqual(0,response.status_code);
  31 + Assert.AreEqual("n/a", response.hits[0].custom_document_no);
  32 + Assert.AreEqual("n/a", response.hits[0].oem_document_no);
  33 + Assert.AreEqual(doc.content.Length + 1,response.hits[0].filesize);
  34 + Assert.AreEqual(doc.title,response.hits[0].title);
  35 + Assert.AreEqual(doc.realFilename,response.hits[0].filename);
  36 +
  37 + response = this._kt.search(this._session, "DocumentId = \""+ response.hits[0].document_id +"\"", "");
  38 +
  39 + Assert.AreEqual(0,response.status_code);
  40 + Assert.AreEqual(doc.content.Length + 1,response.hits[0].filesize);
  41 + Assert.AreEqual(doc.title,response.hits[0].title);
  42 + Assert.AreEqual(doc.realFilename,response.hits[0].filename);
  43 +
  44 + response = this._kt.search(this._session, "Title = \""+ response.hits[0].title +"\"", "");
  45 +
  46 + Assert.AreEqual(0,response.status_code);
  47 + Assert.AreEqual(doc.content.Length + 1,response.hits[0].filesize);
  48 + Assert.AreEqual(doc.title,response.hits[0].title);
  49 + Assert.AreEqual(doc.realFilename,response.hits[0].filename);
  50 +
  51 +
  52 + response = this._kt.search(this._session, "Filename = \""+ response.hits[0].filename +"\"", "");
  53 +
  54 + Assert.AreEqual(0,response.status_code);
  55 + Assert.AreEqual(doc.content.Length + 1,response.hits[0].filesize);
  56 + Assert.AreEqual(doc.title,response.hits[0].title);
  57 + Assert.AreEqual(doc.realFilename,response.hits[0].filename);
  58 +
  59 + doc.deleteFile();
  60 + }
  61 + }
  62 +}
... ...
lib/documentmanagement/DocumentFieldLink.inc
... ... @@ -33,7 +33,7 @@
33 33 require_once(KT_LIB_DIR . "/util/sanitize.inc");
34 34  
35 35 class DocumentFieldLink extends KTEntity {
36   -
  36 +
37 37 /** document field link primary key */
38 38 var $iId;
39 39 /** primary key of document to which field is linked */
... ... @@ -49,9 +49,9 @@ class DocumentFieldLink extends KTEntity {
49 49 'iDocumentFieldId' => 'document_field_id',
50 50 'sValue' => 'value',
51 51 );
52   -
  52 +
53 53 /**
54   - * Default constructor
  54 + * Default constructor
55 55 *
56 56 * @param Primary key of document to which field is linked
57 57 * @param Primary key of field to which document is linked
... ... @@ -65,7 +65,7 @@ class DocumentFieldLink extends KTEntity {
65 65 $this->iDocumentFieldId = $iNewDocumentFieldId;
66 66 $this->sValue = $sNewValue;
67 67 }
68   -
  68 +
69 69 /**
70 70 * Get the document field link primary key
71 71 *
... ... @@ -75,7 +75,7 @@ class DocumentFieldLink extends KTEntity {
75 75 function getId() {
76 76 return $this->iId;
77 77 }
78   -
  78 +
79 79 /**
80 80 * Get the primary key of the document to which the field is linked
81 81 *
... ... @@ -85,7 +85,7 @@ class DocumentFieldLink extends KTEntity {
85 85 function getMetadataVersionId() {
86 86 return $this->iMetadataVersionId;
87 87 }
88   -
  88 +
89 89 /**
90 90 * Set the primary key of the document to which the field is linked
91 91 *
... ... @@ -95,7 +95,7 @@ class DocumentFieldLink extends KTEntity {
95 95 function setMetadataVersionId($iNewValue) {
96 96 $this->iMetadataVersionId = $iNewValue;
97 97 }
98   -
  98 +
99 99 /**
100 100 * Get the primary key of the field to which the document is linked
101 101 *
... ... @@ -105,7 +105,7 @@ class DocumentFieldLink extends KTEntity {
105 105 function getDocumentFieldId() {
106 106 return $this->iDocumentFieldId;
107 107 }
108   -
  108 +
109 109 /**
110 110 * Set the primary key of the field to which the document is related
111 111 *
... ... @@ -115,7 +115,7 @@ class DocumentFieldLink extends KTEntity {
115 115 function setDocumentFieldId($iNewVale) {
116 116 $this->iDocumentFieldId = $iNewValue;
117 117 }
118   -
  118 +
119 119 /**
120 120 * Get the value of the field
121 121 *
... ... @@ -123,9 +123,9 @@ class DocumentFieldLink extends KTEntity {
123 123 *
124 124 */
125 125 function getValue() {
126   - return sanitizeForSQLtoHTML($this->sValue);
  126 + return $this->sValue;
127 127 }
128   -
  128 +
129 129 /**
130 130 * Set the value of the field
131 131 *
... ... @@ -139,7 +139,7 @@ class DocumentFieldLink extends KTEntity {
139 139 function _table () {
140 140 return KTUtil::getTableName('document_fields_link');
141 141 }
142   -
  142 +
143 143 /**
144 144 *
145 145 * Static function. Given a document fields link primary key will create
... ...
lib/documentmanagement/documentutil.inc.php
... ... @@ -106,7 +106,7 @@ class KTDocumentUtil {
106 106 }
107 107  
108 108 // create the document transaction record
109   - $oDocumentTransaction = & new DocumentTransaction($oDocument, $sCheckInComment, 'ktcore.transactions.check_in');
  109 + $oDocumentTransaction = new DocumentTransaction($oDocument, $sCheckInComment, 'ktcore.transactions.check_in');
110 110 $oDocumentTransaction->create();
111 111  
112 112 $oKTTriggerRegistry = KTTriggerRegistry::getSingleton();
... ... @@ -122,6 +122,11 @@ class KTDocumentUtil {
122 122 }
123 123 }
124 124  
  125 + // NEW SEARCH
  126 +
  127 + Indexer::index($oDocument);
  128 +
  129 + /*
125 130 $aTriggers = $oKTTriggerRegistry->getTriggers('content', 'transform');
126 131 foreach ($aTriggers as $aTrigger) {
127 132 $sTrigger = $aTrigger[0];
... ... @@ -132,6 +137,7 @@ class KTDocumentUtil {
132 137 $oTrigger->setDocument($oDocument);
133 138 $oTrigger->transform();
134 139 }
  140 + */
135 141  
136 142 // fire subscription alerts for the checked in document
137 143 $oSubscriptionEvent = new SubscriptionEvent();
... ... @@ -169,10 +175,10 @@ class KTDocumentUtil {
169 175 }
170 176 }
171 177  
172   - $oDocumentTransaction = & new DocumentTransaction($oDocument, $sCheckoutComment, 'ktcore.transactions.check_out');
  178 + $oDocumentTransaction = new DocumentTransaction($oDocument, $sCheckoutComment, 'ktcore.transactions.check_out');
173 179 $oDocumentTransaction->create();
174 180  
175   - // fire subscription alerts for the checked in document
  181 + // fire subscription alerts for the downloaded document
176 182 $oSubscriptionEvent = new SubscriptionEvent();
177 183 $oFolder = Folder::get($oDocument->getFolderID());
178 184 $oSubscriptionEvent->CheckOutDocument($oDocument, $oFolder);
... ... @@ -180,6 +186,45 @@ class KTDocumentUtil {
180 186 return true;
181 187 }
182 188  
  189 + function archive($oDocument, $sReason) {
  190 +
  191 + $this->startTransaction();
  192 + $oDocument->setStatusID(ARCHIVED);
  193 + $res = $oDocument->update();
  194 +
  195 + if (PEAR::isError($res) || ($res === false)) {
  196 + return PEAR::raiseError(_kt('There was a database error while trying to archive this file'));
  197 + }
  198 +
  199 + $oDocumentTransaction = & new DocumentTransaction($oDocument, sprintf(_kt('Document archived: %s'), $sReason), 'ktcore.transactions.update');
  200 + $oDocumentTransaction->create();
  201 +
  202 + $this->commitTransaction();
  203 +
  204 + $oKTTriggerRegistry = KTTriggerRegistry::getSingleton();
  205 + $aTriggers = $oKTTriggerRegistry->getTriggers('archive', 'postValidate');
  206 + foreach ($aTriggers as $aTrigger) {
  207 + $sTrigger = $aTrigger[0];
  208 + $oTrigger = new $sTrigger;
  209 + $aInfo = array(
  210 + 'document' => $oDocument,
  211 + );
  212 + $oTrigger->setInfo($aInfo);
  213 + $ret = $oTrigger->postValidate();
  214 + if (PEAR::isError($ret)) {
  215 + $oDocument->delete();
  216 + return $ret;
  217 + }
  218 + }
  219 +
  220 + // fire subscription alerts for the archived document
  221 + $oSubscriptionEvent = new SubscriptionEvent();
  222 + $oFolder = Folder::get($oDocument->getFolderID());
  223 + $oSubscriptionEvent->ArchivedDocument($oDocument, $oFolder);
  224 +
  225 + return true;
  226 + }
  227 +
183 228 function &_add($oFolder, $sFilename, $oUser, $aOptions) {
184 229 global $default;
185 230  
... ... @@ -204,9 +249,6 @@ class KTDocumentUtil {
204 249 'creatorid' => $oUser->getID(),
205 250 'documenttypeid' => $iDocumentTypeId,
206 251 ));
207   - if (PEAR::isError($oDocument)) {
208   - return $oDocument;
209   - }
210 252  
211 253 // if (is_null($oContents)) {
212 254 // $res = KTDocumentUtil::setIncomplete($oDocument, 'contents');
... ... @@ -244,6 +286,81 @@ class KTDocumentUtil {
244 286 return $oDocument;
245 287 }
246 288  
  289 + // Overwrite the document
  290 + function overwrite($oDocument, $sFilename, $sTempFileName, $oUser, $aOptions) {
  291 + //$oDocument, $sFilename, $sCheckInComment, $oUser, $aOptions = false
  292 + $oStorage =& KTStorageManagerUtil::getSingleton();
  293 + $iFileSize = filesize($sTempFileName);
  294 +
  295 + // Check that document is not checked out
  296 + if($oDocument->getIsCheckedOut()) {
  297 + return PEAR::raiseError(_kt('Document is checkout and cannot be overwritten'));
  298 + }
  299 +
  300 + if (!$oStorage->upload($oDocument, $sTempFileName)) {
  301 + return PEAR::raiseError(_kt('An error occurred while storing the new file'));
  302 + }
  303 +
  304 + $oDocument->setLastModifiedDate(getCurrentDateTime());
  305 + $oDocument->setModifiedUserId($oUser->getId());
  306 +
  307 + $oDocument->setFileSize($iFileSize);
  308 +
  309 + $sOriginalFilename = $oDocument->getFileName();
  310 +
  311 + if($sOriginalFilename != $sFilename){
  312 + if(strlen($sFilename)) {
  313 + global $default;
  314 + $oDocument->setFileName($sFilename);
  315 + $default->log->info('renamed document ' . $oDocument->getId() . ' to ' . $sFilename);
  316 + }
  317 + $oDocument->setMinorVersionNumber($oDocument->getMinorVersionNumber()+1);
  318 + }
  319 +
  320 + $sType = KTMime::getMimeTypeFromFile($sFilename);
  321 + $iMimeTypeId = KTMime::getMimeTypeID($sType, $oDocument->getFileName());
  322 + $oDocument->setMimeTypeId($iMimeTypeId);
  323 +
  324 + $bSuccess = $oDocument->update();
  325 + if ($bSuccess !== true) {
  326 + if (PEAR::isError($bSuccess)) {
  327 + return $bSuccess;
  328 + }
  329 + return PEAR::raiseError(_kt('An error occurred while storing this document in the database'));
  330 + }
  331 +/*
  332 + // create the document transaction record
  333 + $oDocumentTransaction = new DocumentTransaction($oDocument, $sCheckInComment, 'ktcore.transactions.check_in');
  334 + $oDocumentTransaction->create();
  335 +
  336 + $oKTTriggerRegistry = KTTriggerRegistry::getSingleton();
  337 + $aTriggers = $oKTTriggerRegistry->getTriggers('content', 'scan');
  338 + foreach ($aTriggers as $aTrigger) {
  339 + $sTrigger = $aTrigger[0];
  340 + $oTrigger = new $sTrigger;
  341 + $oTrigger->setDocument($oDocument);
  342 + $ret = $oTrigger->scan();
  343 + if (PEAR::isError($ret)) {
  344 + $oDocument->delete();
  345 + return $ret;
  346 + }
  347 + }
  348 +
  349 + // NEW SEARCH
  350 +
  351 + Indexer::index($oDocument);
  352 +
  353 +
  354 + // fire subscription alerts for the checked in document
  355 + $oSubscriptionEvent = new SubscriptionEvent();
  356 + $oFolder = Folder::get($oDocument->getFolderID());
  357 + $oSubscriptionEvent->CheckinDocument($oDocument, $oFolder);
  358 +
  359 + KTDocumentUtil::updateSearchableText($oDocument);
  360 +*/
  361 + return true;
  362 + }
  363 +
247 364 // {{{ validateMetadata
248 365 function validateMetadata(&$oDocument, $aMetadata) {
249 366 $aFieldsets =& KTFieldset::getGenericFieldsets();
... ... @@ -425,34 +542,15 @@ class KTDocumentUtil {
425 542 // {{{ _in_add
426 543 function &_in_add($oFolder, $sFilename, $oUser, $aOptions) {
427 544 $aOrigOptions = $aOptions;
428   - if (KTDocumentUtil::fileExists($oFolder, $sFilename)) {
429   - $oDoc = Document::getByFilenameAndFolder($sFilename, $oFolder->getId());
430   - if (PEAR::isError($oDoc)) {
431   - return PEAR::raiseError(_kt('Document with that filename already exists in this folder, and appears to be invalid. Please contact the system administrator.'));
432   - } else {
433   - if ($oDoc->getStatusID() != LIVE) {
434   - $sError = _kt('Document with that filename already exists in this folder, but it has been archived or deleted and is still available for restoration. To prevent it being overwritten, you are not allowed to add a document with the same title or filename.');
435   - } else {
436   - $sError = _kt('Document with that filename already exists in this folder.');
437   - }
438   -
439   - $sError .= _kt(' Document') . ': ' . $oDoc->getName() . ' (ID:' . $oDoc->getId() . ')';
440   - return PEAR::raiseError($sError);
441   - }
  545 + while(KTDocumentUtil::fileExists($oFolder, $sFilename)) {
  546 + $oDoc = Document::getByFilenameAndFolder($sFilename, $oFolder->getId());
  547 + $sFilename = KTDocumentUtil::generateNewDocumentFilename($oDoc->getFileName());
442 548 }
443 549 $sName = KTUtil::arrayGet($aOptions, 'description', $sFilename);
444   - if (KTDocumentUtil::nameExists($oFolder, $sName)) {
445   - $oDoc = Document::getByNameAndFolder($sName, $oFolder->getId());
446   - if (PEAR::isError($oDoc)) {
447   - return PEAR::raiseError(_kt('Document with that title already exists in this folder, and appears to be invalid. Please contact the system administrator.'));
448   - } else {
449   - if ($oDoc->getStatusID != LIVE) {
450   - return PEAR::raiseError(_kt('Document with that title already exists in this folder, but it has been archived or deleted and is still available for restoration. To prevent it being overwritten, you are not allowed to add a document with the same title or filename.'));
451   - } else {
452   - return PEAR::raiseError(_kt('Document with that title already exists in this folder.'));
453   - }
454   - }
455   -
  550 + while(KTDocumentUtil::nameExists($oFolder, $sName)) {
  551 + $oDoc = Document::getByNameAndFolder($sName, $oFolder->getId());
  552 + $aOptions['description'] = KTDocumentUtil::generateNewDocumentName($oDoc->getName());
  553 + $sName = KTDocumentUtil::generateNewDocumentName($oDoc->getName());
456 554 }
457 555  
458 556 $oUploadChannel =& KTUploadChannel::getSingleton();
... ... @@ -479,6 +577,10 @@ class KTDocumentUtil {
479 577 }
480 578 }
481 579  
  580 + // NEW SEARCH
  581 +
  582 + Indexer::index($oDocument);
  583 + /*
482 584 $oUploadChannel->sendMessage(new KTUploadGenericMessage(_kt('Transforming file')));
483 585 $oKTTriggerRegistry = KTTriggerRegistry::getSingleton();
484 586 $aTriggers = $oKTTriggerRegistry->getTriggers('content', 'transform');
... ... @@ -491,12 +593,12 @@ class KTDocumentUtil {
491 593 $oTrigger->setDocument($oDocument);
492 594 // $oUploadChannel->sendMessage(new KTUploadGenericMessage(sprintf(_kt(" (trigger %s)"), $sTrigger)));
493 595 $oTrigger->transform();
494   - }
  596 + }*/
495 597  
496 598 // $oUploadChannel->sendMessage(new KTUploadGenericMessage(_kt('Creating transaction')));
497 599 $aOptions = array('user' => $oUser);
498 600 //create the document transaction record
499   - $oDocumentTransaction = & new DocumentTransaction($oDocument, _kt('Document created'), 'ktcore.transactions.create', $aOptions);
  601 + $oDocumentTransaction = new DocumentTransaction($oDocument, _kt('Document created'), 'ktcore.transactions.create', $aOptions);
500 602 $res = $oDocumentTransaction->create();
501 603 if (PEAR::isError($res)) {
502 604 $oDocument->delete();
... ... @@ -531,6 +633,45 @@ class KTDocumentUtil {
531 633 }
532 634 // }}}
533 635  
  636 + function generateNewDocumentFilename($sDocFilename){
  637 + if(preg_match("/\([0-9]+\)(\.[^\.]+){1,}$/", $sDocFilename)){
  638 + preg_match("/\([0-9]+\)\./", $sDocFilename, $matches);
  639 + $new_one = substr($matches[0], 1);
  640 + $new_two = explode(')', $new_one);
  641 + $new = $new_two[0]+1;
  642 +
  643 + $pattern[0] = '/\([0-9]+\)\./';
  644 + $replacement[0] = ' ('.$new.').';
  645 + $sFilename = preg_replace($pattern, $replacement, $sDocFilename);
  646 + }else{
  647 + $matches = explode('.', $sDocFilename);
  648 + $prefix = $matches[0].' (2)';
  649 + for($i = 1; $i < count($matches); $i++ ){
  650 + $suffix .= '.'.$matches[$i];
  651 + }
  652 + $sFilename = $prefix.$suffix;
  653 + }
  654 +
  655 + return $sFilename;
  656 + }
  657 +
  658 + function generateNewDocumentName($sDocName){
  659 + if(preg_match("/\([0-9]+\)$/", $sDocName)){
  660 + preg_match("/\([0-9]+\)$/", $sDocName, $matches);
  661 + $new_one = substr($matches[0], 1);
  662 + $new_two = explode(')', $new_one);
  663 + $new = $new_two[0]+1;
  664 +
  665 + $pattern[0] = '/\([0-9]+\)$/';
  666 + $replacement[0] = '('.$new.')';
  667 + $sName = preg_replace($pattern, $replacement, $sDocName);
  668 + }else{
  669 + $sName = $sDocName.' (2)';
  670 + }
  671 +
  672 + return $sName;
  673 + }
  674 +
534 675 // {{{ fileExists
535 676 function fileExists($oFolder, $sFilename) {
536 677 return Document::fileExists($sFilename, $oFolder->getID());
... ... @@ -571,7 +712,7 @@ class KTDocumentUtil {
571 712 $iMimeTypeId = KTMime::getMimeTypeID($sType, $oDocument->getFileName());
572 713 $oDocument->setMimeTypeId($iMimeTypeId);
573 714  
574   - $res = $oStorage->upload($oDocument, $sFilename);
  715 + $res = $oStorage->upload($oDocument, $sFilename, $aOptions);
575 716 if ($res === false) {
576 717 return PEAR::raiseError(sprintf(_kt("Couldn't store contents: %s"), _kt('No reason given')));
577 718 }
... ... @@ -590,6 +731,11 @@ class KTDocumentUtil {
590 731  
591 732 // {{{ updateTransactionText
592 733 function updateTransactionText($oDocument) {
  734 +
  735 + // NEW SEARCH
  736 +
  737 + return;
  738 +
593 739 $iDocumentId = KTUtil::getId($oDocument);
594 740 $aTransactions = DocumentTransaction::getByDocument($iDocumentId);
595 741 foreach ($aTransactions as $oTransaction) {
... ... @@ -612,6 +758,10 @@ class KTDocumentUtil {
612 758  
613 759 // {{{ updateSearchableText
614 760 function updateSearchableText($oDocument, $bOverride = false) {
  761 +
  762 + // NEW SEARCH
  763 + return;
  764 +
615 765 if (isset($GLOBALS['_IN_ADD']) && empty($bOverride)) {
616 766 return;
617 767 }
... ... @@ -716,7 +866,7 @@ class KTDocumentUtil {
716 866 return PEAR::raiseError(_kt('There was a problem deleting the document from storage.'));
717 867 }
718 868  
719   - $oDocumentTransaction = & new DocumentTransaction($oDocument, _kt('Document deleted: ') . $sReason, 'ktcore.transactions.delete');
  869 + $oDocumentTransaction = new DocumentTransaction($oDocument, _kt('Document deleted: ') . $sReason, 'ktcore.transactions.delete');
720 870 $oDocumentTransaction->create();
721 871  
722 872 $oDocument->setFolderID(1);
... ... @@ -752,6 +902,14 @@ class KTDocumentUtil {
752 902 // }}}
753 903  
754 904 function reindexDocument($oDocument) {
  905 +
  906 + // NEW SEARCH
  907 +
  908 + Indexer::index($oDocument);
  909 +
  910 + return;
  911 +
  912 + /*
755 913 $oKTTriggerRegistry = KTTriggerRegistry::getSingleton();
756 914 $aTriggers = $oKTTriggerRegistry->getTriggers('content', 'transform');
757 915 foreach ($aTriggers as $aTrigger) {
... ... @@ -763,7 +921,7 @@ class KTDocumentUtil {
763 921 $oTrigger->setDocument($oDocument);
764 922 $oTrigger->transform();
765 923 }
766   - KTDocumentUtil::updateSearchableText($oDocument);
  924 + KTDocumentUtil::updateSearchableText($oDocument);*/
767 925 }
768 926  
769 927  
... ... @@ -778,7 +936,7 @@ class KTDocumentUtil {
778 936 }
779 937  
780 938  
781   - function copy($oDocument, $oDestinationFolder, $sReason = null) {
  939 + function copy($oDocument, $oDestinationFolder, $sReason = null, $sDestinationDocName = null) {
782 940 // 1. generate a new triad of content, metadata and core objects.
783 941 // 2. update the storage path.
784 942 //print '--------------------------------- BEFORE';
... ... @@ -797,23 +955,36 @@ class KTDocumentUtil {
797 955 // we still have a bogus md_version, but integrity holds, so fix it now.
798 956 $oCore = KTDocumentCore::get($id);
799 957  
  958 + // Get the metadata version for the source document
800 959 $sTable = KTUtil::getTableName('document_metadata_version');
801 960 $sQuery = 'SELECT * FROM ' . $sTable . ' WHERE id = ?';
802 961 $aParams = array($oDocument->getMetadataVersionId());
803 962 $aMDRow = DBUtil::getOneResult(array($sQuery, $aParams));
804 963 unset($aMDRow['id']);
  964 +
  965 + // Copy the source metadata into the destination document
805 966 $aMDRow['document_id'] = $oCore->getId();
  967 + if(!empty($sDestinationDocName)){
  968 + $aMDRow['name'] = $sDestinationDocName;
  969 + $aMDRow['description'] = $sDestinationDocName;
  970 + }
806 971 $id = DBUtil::autoInsert($sTable, $aMDRow);
807 972 if (PEAR::isError($id)) { return $id; }
808 973 $oCore->setMetadataVersionId($id);
809 974 $oMDV = KTDocumentMetadataVersion::get($id);
810 975  
  976 + // Get the content version for the source document
811 977 $sTable = KTUtil::getTableName('document_content_version');
812 978 $sQuery = 'SELECT * FROM ' . $sTable . ' WHERE id = ?';
813 979 $aParams = array($oDocument->_oDocumentContentVersion->getId());
814 980 $aContentRow = DBUtil::getOneResult(array($sQuery, $aParams));
815 981 unset($aContentRow['id']);
  982 +
  983 + // Copy the source content into the destination document
816 984 $aContentRow['document_id'] = $oCore->getId();
  985 + if(!empty($sDestinationDocName)){
  986 + $aContentRow['filename'] = $sDestinationDocName;
  987 + }
817 988 $id = DBUtil::autoInsert($sTable, $aContentRow);
818 989 if (PEAR::isError($id)) { return $id; }
819 990 $oMDV->setContentVersionId($id);
... ... @@ -835,6 +1006,10 @@ class KTDocumentUtil {
835 1006 $res = KTDocumentUtil::copyMetadata($oNewDocument, $oDocument->getMetadataVersionId());
836 1007 if (PEAR::isError($res)) { return $res; }
837 1008  
  1009 + // Ensure the copied document is not checked out
  1010 + $oNewDocument->setIsCheckedOut(false);
  1011 + $oNewDocument->setCheckedOutUserID(-1);
  1012 +
838 1013 // finally, copy the actual file.
839 1014 $oStorage =& KTStorageManagerUtil::getSingleton();
840 1015 $res = $oStorage->copy($oDocument, $oNewDocument);
... ... @@ -851,6 +1026,11 @@ class KTDocumentUtil {
851 1026 $res = $oNewDocument->update();
852 1027 if (PEAR::isError($res)) { return $res; }
853 1028  
  1029 + // NEW SEARCH
  1030 +
  1031 +
  1032 + /*
  1033 +
854 1034 $sTable = KTUtil::getTableName('document_text');
855 1035 $aQuery = array("SELECT document_text FROM $sTable WHERE document_id = ?", array($oDocument->getId()));
856 1036 $sData = DBUtil::getOneResultKey($aQuery, 'document_text');
... ... @@ -860,6 +1040,8 @@ class KTDocumentUtil {
860 1040 'document_text' => $contents,
861 1041 );
862 1042 DBUtil::autoInsert($sTable, $aInsertValues, array('noid' => true));
  1043 +
  1044 + */
863 1045 KTDocumentUtil::updateSearchableText($oNewDocument);
864 1046 KTPermissionUtil::updatePermissionLookup($oNewDocument);
865 1047  
... ... @@ -867,14 +1049,36 @@ class KTDocumentUtil {
867 1049 $sReason = '';
868 1050 }
869 1051  
870   -
871   - $oDocumentTransaction = & new DocumentTransaction($oDocument, sprintf(_kt("Copied to folder \"%s\". %s"), $oDestinationFolder->getName(), $sReason), 'ktcore.transactions.copy');
  1052 + $oDocumentTransaction = new DocumentTransaction($oDocument, sprintf(_kt("Copied to folder \"%s\". %s"), $oDestinationFolder->getName(), $sReason), 'ktcore.transactions.copy');
872 1053 $oDocumentTransaction->create();
873 1054  
874 1055 $oSrcFolder = Folder::get($oDocument->getFolderID());
875   - $oDocumentTransaction = & new DocumentTransaction($oNewDocument, sprintf(_kt("Copied from original in folder \"%s\". %s"), $oSrcFolder->getName(), $sReason), 'ktcore.transactions.copy');
  1056 + $oDocumentTransaction = new DocumentTransaction($oNewDocument, sprintf(_kt("Copied from original in folder \"%s\". %s"), $oSrcFolder->getName(), $sReason), 'ktcore.transactions.copy');
876 1057 $oDocumentTransaction->create();
877 1058  
  1059 +
  1060 + $oKTTriggerRegistry = KTTriggerRegistry::getSingleton();
  1061 + $aTriggers = $oKTTriggerRegistry->getTriggers('copyDocument', 'postValidate');
  1062 + foreach ($aTriggers as $aTrigger) {
  1063 + $sTrigger = $aTrigger[0];
  1064 + $oTrigger = new $sTrigger;
  1065 + $aInfo = array(
  1066 + 'document' => $oNewDocument,
  1067 + 'old_folder' => $oSrcFolder,
  1068 + 'new_folder' => $oDestinationFolder,
  1069 + );
  1070 + $oTrigger->setInfo($aInfo);
  1071 + $ret = $oTrigger->postValidate();
  1072 + if (PEAR::isError($ret)) {
  1073 + return $ret;
  1074 + }
  1075 + }
  1076 +
  1077 + // fire subscription alerts for the copied document
  1078 + $oSubscriptionEvent = new SubscriptionEvent();
  1079 + $oFolder = Folder::get($oDocument->getFolderID());
  1080 + $oSubscriptionEvent->MoveDocument($oDocument, $oDestinationFolder, $oSrcFolder, 'CopiedDocument');
  1081 +
878 1082 return $oNewDocument;
879 1083 }
880 1084  
... ... @@ -907,7 +1111,7 @@ class KTDocumentUtil {
907 1111 }
908 1112  
909 1113 // create the document transaction record
910   - $oDocumentTransaction = & new DocumentTransaction($oDocument, _kt('Document renamed'), 'ktcore.transactions.update');
  1114 + $oDocumentTransaction = new DocumentTransaction($oDocument, _kt('Document renamed'), 'ktcore.transactions.update');
911 1115 $oDocumentTransaction->create();
912 1116  
913 1117 // fire subscription alerts for the checked in document
... ... @@ -959,7 +1163,7 @@ class KTDocumentUtil {
959 1163  
960 1164 // create the document transaction record
961 1165  
962   - $oDocumentTransaction = & new DocumentTransaction($oDocument, $sMoveMessage, 'ktcore.transactions.move');
  1166 + $oDocumentTransaction = new DocumentTransaction($oDocument, $sMoveMessage, 'ktcore.transactions.move');
963 1167 $oDocumentTransaction->create();
964 1168  
965 1169  
... ... @@ -980,15 +1184,79 @@ class KTDocumentUtil {
980 1184 }
981 1185 }
982 1186  
  1187 + // fire subscription alerts for the moved document
  1188 + $oSubscriptionEvent = new SubscriptionEvent();
  1189 + $oSubscriptionEvent->MoveDocument($oDocument, $oFolder, $oOriginalFolder);
  1190 +
983 1191 return KTPermissionUtil::updatePermissionLookup($oDocument);
984 1192 }
985 1193  
  1194 + /**
  1195 + * Delete a selected version of the document.
  1196 + */
  1197 + function deleteVersion($oDocument, $iVersionID, $sReason){
  1198 +
  1199 + $oDocument =& KTUtil::getObject('Document', $oDocument);
  1200 + $oVersion =& KTDocumentMetadataVersion::get($iVersionID);
  1201 +
  1202 + $oStorageManager =& KTStorageManagerUtil::getSingleton();
  1203 +
  1204 + global $default;
  1205 +
  1206 + if (empty($sReason)) {
  1207 + return PEAR::raiseError(_kt('Deletion requires a reason'));
  1208 + }
  1209 +
  1210 + if (PEAR::isError($oDocument) || ($oDocument == false)) {
  1211 + return PEAR::raiseError(_kt('Invalid document object.'));
  1212 + }
  1213 +
  1214 + if (PEAR::isError($oVersion) || ($oVersion == false)) {
  1215 + return PEAR::raiseError(_kt('Invalid document version object.'));
  1216 + }
  1217 +
  1218 + $iContentId = $oVersion->getContentVersionId();
  1219 + $oContentVersion = KTDocumentContentVersion::get($iContentId);
  1220 +
  1221 + if (PEAR::isError($oContentVersion) || ($oContentVersion == false)) {
  1222 + DBUtil::rollback();
  1223 + return PEAR::raiseError(_kt('Invalid document content version object.'));
  1224 + }
  1225 +
  1226 + DBUtil::startTransaction();
  1227 +
  1228 + // now delete the document version
  1229 + $res = $oStorageManager->deleteVersion($oVersion);
  1230 + if (PEAR::isError($res) || ($res == false)) {
  1231 + //could not delete the document version from the file system
  1232 + $default->log->error('Deletion: Filesystem error deleting the metadata version ' .
  1233 + $oVersion->getMetadataVersion() . ' of the document ' .
  1234 + $oDocument->getFileName() . ' from folder ' .
  1235 + Folder::getFolderPath($oDocument->getFolderID()) .
  1236 + ' id=' . $oDocument->getFolderID());
  1237 +
  1238 + // we use a _real_ transaction here ...
  1239 +
  1240 + DBUtil::rollback();
  1241 +
  1242 + return PEAR::raiseError(_kt('There was a problem deleting the document from storage.'));
  1243 + }
  1244 +
  1245 + // change status for the metadata version
  1246 + $oVersion->setStatusId(VERSION_DELETED);
  1247 + $oVersion->update();
  1248 +
  1249 + // set the storage path to empty
  1250 +// $oContentVersion->setStoragePath('');
  1251 +
  1252 + DBUtil::commit();
  1253 + }
986 1254 }
987 1255  
988 1256 class KTMetadataValidationError extends PEAR_Error {
989 1257 function KTMetadataValidationError ($aFailed) {
990 1258 $this->aFailed = $aFailed;
991   - $message = _kt('Validation Failed');
  1259 + $message = _kt('Please be sure to enter information for all the Required fields below');
992 1260 parent::PEAR_Error($message);
993 1261 }
994 1262 }
... ...
lib/util/sanitize.inc
... ... @@ -51,13 +51,13 @@ function sanitize($string) {
51 51 }
52 52  
53 53 function sanitizeForSQL($string, $min='', $max='') {
54   -
  54 +
55 55 $string = trim($string);
56 56 if(get_magic_quotes_gpc()) $string = stripslashes($string);
57   -
  57 +
58 58 $len = strlen($string);
59 59 if((($min != '') && ($len < $min)) || (($max != '') && ($len > $max))) return false;
60   -
  60 +
61 61 if(function_exists("mysql_real_escape_string")) {
62 62 return mysql_real_escape_string($string);
63 63 } else {
... ... @@ -65,12 +65,10 @@ function sanitizeForSQL($string, $min=&#39;&#39;, $max=&#39;&#39;) {
65 65 }
66 66 }
67 67  
68   -function sanitizeForSQLtoHTML($string, $min='', $max='') {
69   -
70   - $string = str_ireplace("\r", "", $string);
71   - $string = str_ireplace("\n", "", $string);
72   - return stripslashes(trim($string));
73   -
  68 +function sanitizeForSQLtoHTML($string, $min='', $max='')
  69 +{
  70 + $string = str_replace(array("\r","\n"), array('',''), $string);
  71 + return $string;
74 72 }
75 73  
76 74 function sanitizeForHTML($string, $min='', $max='')
... ... @@ -80,7 +78,7 @@ function sanitizeForHTML($string, $min=&#39;&#39;, $max=&#39;&#39;)
80 78  
81 79 $len = strlen($string);
82 80 if((($min != '') && ($len < $min)) || (($max != '') && ($len > $max))) return false;
83   -
  81 +
84 82 if(function_exists("htmlspecialchars")) {
85 83 return htmlspecialchars($string);
86 84 } else {
... ... @@ -117,8 +115,8 @@ function sanitizeForSYSTEM($string, $min=&#39;&#39;, $max=&#39;&#39;)
117 115  
118 116 $len = strlen($string);
119 117 if((($min != '') && ($len < $min)) || (($max != '') && ($len > $max))) return false;
120   -
121   - $pattern = '/( ;|\||`|>|<|&|^|"|'."\n|\r|'".'|{|}|[|]|\)|\( )/i';
  118 +
  119 + $pattern = '/( ;|\||`|>|<|&|^|"|'."\n|\r|'".'|{|}|[|]|\)|\( )/i';
122 120 $string = preg_replace( $pattern, '', $string);
123 121 return '"'.preg_replace( '/\$/', '\\\$', $string).'"';
124 122 }
... ...