private void recreatePartTypes() { List<String> partTypes = new ArrayList<String>(); for (CatalogObjectPart part: parts){ partTypes.add(part.getType()); } this.partTypes = partTypes.toArray(new String[partTypes.size()]); } }
/** * Returns the part of the object which has the specified type. * * @param type type of the part to return * @return the part found, null if the object does not have a part with this type */ public CatalogObjectPart<T> getPart(String type) { for (CatalogObjectPart<T> part : getParts()) if (part.getType().equals(type)) return part; return null; }
/** * Uses a configured extractor to find the value of the search_key field * for a catalog data part and returns it. * * @param part the catalog part to extract data from * @return the field to store in the database */ Map<String, Object> extractExtraField(CatalogObjectPart<String> part) { String value = null; PartKeyExtractor e = extractors.get(part.getType()); if (e != null) value = e.extract(part); return Collections.<String,Object>singletonMap(PART_SEARCH_KEY, value); }
private CatalogObjectPart<String> findPreferedPart(Set<CatalogObjectPart<String>> parts) { String[] partPreferences = preparePartPreferences(); if (partPreferences == null || partPreferences.length == 0) { logger.warn("Prefered parts not defined. First one will be used."); Iterator<CatalogObjectPart<String>> iterator = parts.iterator(); if (iterator.hasNext()) { return iterator.next(); } else { return null; } } for (String partName : partPreferences) { for (CatalogObjectPart<String> candidatePart : parts) { String candidateName = pathPrefix + candidatePart.getType(); if (candidateName.equals(partName)) { return candidatePart; } } } return null; }
@Override protected void savePart(long fk, CatalogObjectPart<String> part) { jdbc.update( "INSERT INTO "+tablePrefix+PARTS_TABLE_NAME+ '('+PART_FK+','+PART_TYPE+','+PART_DATA+','+PART_STAMP+") VALUES (?,?,?,?)", fk, part.getType(), part.getData(), new Date() ); }
/** * Removes from a catalog object all parts with ttransient types. * * @param co the object to modify */ private void removeTransientParts(CatalogObject<String> co) { Set<CatalogObjectPart<String>> pts = co.getParts(); Iterator<CatalogObjectPart<String>> it = pts.iterator(); while (it.hasNext()) { CatalogObjectPart<String> pt = it.next(); PartType t = curdao.knownType(pt.getType()); if (isTransient(t)) it.remove(); } }
@Override public EnrichedPayload<YElement>[] process(CatalogObject<String> input, ProcessContext ctx) { for (CatalogObjectPart<String> part : input.getParts()) { if (part.getType().equals(CatalogParamConstants.TYPE_BWMETA2)) { log.info("data: \n {}", part.getData()); } } return super.process(input, ctx); } }
@Override public BatchResult batch(final Collection<EditorOperation> operations, final EXECUTION_MODE mode) throws EditorException { for (final EditorOperation oper:operations) { if (oper instanceof SaveOperation) { final SaveOperation<String> op=(SaveOperation<String>) oper; for (final CatalogObjectPart<String> pa:op.getObject().getParts()){ if (pa.getType().equalsIgnoreCase(partType)) { try { queue.put(pa.getData()); } catch (final InterruptedException ex) { LoggerFactory.getLogger(FakeFacadesBeingIterator.class).error("Exception caught", ex); } } } } } return new BatchResult(null, new ArrayList<CatalogObjectMeta>()); }
/** * Saves a new data part with a specified foreign key. * * @param fk the foreign key (metadata pk) for the part * @param part the part to save */ protected void savePart(long fk, CatalogObjectPart<String> part) { Map<String, Object> extra = extraFieldsForPartSave(part); String query = "INSERT INTO "+tablePrefix+PARTS_TABLE_NAME+ '('+PART_FK+','+PART_TYPE+','+PART_DATA; Object[] params = new Object[3+extra.size()]; params[0] = fk; params[1] = part.getType(); params[2] = part.getData(); int n = 3; for (Entry<String, Object> e : extra.entrySet()) { query += ","+e.getKey(); params[n] = e.getValue(); n+=1; } query += ") VALUES (?,?,?"+StringUtils.repeat(",?", extra.size())+")"; jdbc.update(query, params); }
/** * Updates a data part with a specified foreign key and a specific type. * * @param fk the foreign key (metadata pk) for the part * @param part the part to update */ protected void updatePart(long fk, CatalogObjectPart<String> part) throws DataAccessException { Map<String, Object> extra = extraFieldsForPartUpdate(part); String query = "UPDATE "+tablePrefix+PARTS_TABLE_NAME+" SET "+PART_DATA+"=?"; Object[] params = new Object[3+extra.size()]; params[0] = part.getData(); int n = 1; for (Entry<String, Object> e : extra.entrySet()) { query += ","+e.getKey()+"=?"; params[n] = e.getValue(); n+=1; } String where = " WHERE "+PART_FK+"=? AND "+PART_TYPE+"=?"; params[params.length-2] = fk; params[params.length-1] = part.getType(); jdbc.update(query+where, params); }
/** * Checks if the requested changes to a catalog object only affect transient parts and tags. * * @param cur current object metadata * @param co the new object to save * @param drop the types to delete * @return true if there are only changes to transient parts and tags, false otherwise */ private boolean onlyTransientChanges(CatalogObjectMeta cur, CatalogObject<String> co, String[] drop) { HashSet<String> curTs = new HashSet<String>(Arrays.asList(cur.getTags())); for (Iterator<String> it = curTs.iterator(); it.hasNext();) if (it.next().startsWith(transientTagPrefix)) it.remove(); HashSet<String> newTs = new HashSet<String>(Arrays.asList(co.getTags())); for (Iterator<String> it = newTs.iterator(); it.hasNext();) if (it.next().startsWith(transientTagPrefix)) it.remove(); if (!curTs.equals(newTs)) return false; for (CatalogObjectPart<String> pt : co.getParts()) { PartType t = curdao.knownType(pt.getType()); if (!isTransient(t)) return false; } for (String tn : drop) { PartType t = curdao.knownType(tn); if (!isTransient(t)) return false; } return true; }
@Override public CatalogObjectMeta save(CatalogObject<String> co) { DbObjectMeta saved = save((CatalogObjectMeta) co); Set<String> ts = new HashSet<String>(); for (CatalogObjectPart<String> pt : co.getParts()) { savePart(saved.getPK(), pt); ts.add(pt.getType()); } saved.setPartTypes(ts.toArray(new String[ts.size()])); return new CatalogObjectMeta(saved); }
mav.addObject("mimetype", part.getType()); mav.addObject("timestamp", part.getTimestamp().toString());
private ModelAndView showElementInfo(String elementId, String partId, String format) { Map<String, Object> model = new HashMap<String, Object>(); try { CatalogObject<String> object = catalogFacade .getObject(new YaddaObjectID(elementId, null, null)); model.put("objectData", object); if (object != null && StringUtils.isNotBlank(partId)) { CatalogObjectPart<String> part = catalogFacade.getPart( object.getId(), partId, null); if (part != null && part.getData() != null) { model.put("partId", part.getType()); model.put("part", part.getData()); } else { model.put("part", ""); } } } catch (CatalogException e) { throw new SystemException(Modules.CATALOG, e.getMessage(), e); } ModelAndView mdv; if (format != null && format.equals("raw")) { mdv = new ModelAndView(rawView, "catalog", model); } else { mdv = new ModelAndView(catalogView, "catalog", model); } return mdv; }
if(part.getType().equals(CatalogParamConstants.TYPE_BWMETA2)){ yExportList = transformer.read(part.getData(), null); for(YExportable yElemExport : yExportList)
@Override public CatalogObjectMeta update(DbObjectMeta current, CatalogObject<String> co) { CatalogObjectMeta updated = co; if (!current.getId().equals(co.getId())) updated = update(current, (CatalogObjectMeta) co); else updateTags(current, co); Set<String> present = new HashSet<String>(Arrays.asList(current.getPartTypes())); for (CatalogObjectPart<String> pt : co.getParts()) { if (present.contains(pt.getType())) updatePart(current.getPK(), pt); else { savePart(current.getPK(), pt); present.add(pt.getType()); } } updated.setPartTypes(present.toArray(new String[present.size()])); return updated; }
boolean goFor2nd = false; //DEBUG for(CatalogObjectPart<String> part : catObject.getParts()){ if (!part.getType().equals(CatalogParamConstants.TYPE_BWMETA2)) continue;
/** * Creates a catalog object from metadata and if it is not historical finds * and fills its parts and part types. * * @param meta the metadata for the catalog object * @return a catalog object * @throws DataAccessException on database errors */ private CatalogObject<String> makeObject(DbObjectMeta meta) throws DataAccessException { CatalogObject<String> ret; ret = new CatalogObject<String>(meta); if (!meta.isHistorical()) { Set<CatalogObjectPart<String>> parts = findParts(meta.getPK()); ret.setParts(parts); String[] partTypes = new String[parts.size()]; int i = 0; for (CatalogObjectPart<String> part : parts) { partTypes[i] = part.getType(); i += 1; } ret.setPartTypes(partTypes); } return ret; }
/** * Creates a catalog object from passed current metadata and its part with * the specified type. * * @param meta the metadata for the catalog object * @param type type of the part to find * @return a catalog object with a single part and a one-element partTypes property * @throws EmptyResultDataAccessException if no matching part found * @throws DataAccessException on database errors */ private CatalogObject<String> makeObject(DbObjectMeta meta, String type) throws DataAccessException { CatalogObject<String> ret; CatalogObjectPart<String> part = findPart(meta.getPK(), type); ret = new CatalogObject<String>(meta); ret.addPart(part); ret.setPartTypes(new String[] { part.getType() }); return ret; }