/** * Returns the target types that need to have conversion. The types contain first as many * constructor parameter types as we have and then the types of properties of object as given by * names of result-set. */ @NotNull private static Optional<List<Type>> findTargetTypes( @NotNull Constructor<?> ctor, @NotNull List<String> resultSetColumns) { List<Type> constructorParameterTypes = asList(ctor.getGenericParameterTypes()); int constructorParameterCount = constructorParameterTypes.size(); if (constructorParameterCount > resultSetColumns.size()) { // We don't have enough columns in ResultSet to instantiate this constructor, discard it. return Optional.empty(); } else if (constructorParameterCount == resultSetColumns.size()) { // We have exactly enough column in ResultSet. Use the constructor as it is. return Optional.of(constructorParameterTypes); } else { // Get the types of remaining properties ArrayList<Type> result = new ArrayList<>(resultSetColumns.size()); result.addAll(constructorParameterTypes); List<String> propertyNames = resultSetColumns.subList(constructorParameterCount, resultSetColumns.size()); for (String name : propertyNames) { Type type = PropertyAccessor.findPropertyType(ctor.getDeclaringClass(), name).orElse(null); if (type != null) result.add(type); else return Optional.empty(); } return Optional.of(result); } }
@NotNull private static PropertyAccessor createAccessor( int index, @NotNull Class<?> cl, @NotNull List<String> names) { return PropertyAccessor.findAccessor(cl, names.get(index)) .orElseThrow( () -> new InstantiationFailureException( "Could not find neither setter nor field for '" + names.get(index) + '\'')); }
private DataElementConcept existingMapping(DataElementConcept dec) { List<String> eager = new ArrayList<String>(); eager.add(EagerConstants.AC_CS_CSI); List<DataElementConcept> l = dataElementConceptDAO.find(dec, eager); if (l.size() == 0) throw new PersisterException( PropertyAccessor.getProperty("dec.existing.error", ConventionUtil.publicIdVersion(dec))); DataElementConcept existingDec = l.get(0); return existingDec; }
void init() { contexts = cadsrModule.getAllContexts(); int contentCount = contextComboBox.getItemCount(); int i = 0; while (i <= contentCount && contentCount != 0) { contextComboBox.removeItemAt(i); contentCount = contextComboBox.getItemCount(); } for (Context _con : contexts) { contextComboBox.addItem(_con.getName()); } contextComboBox.setSelectedItem(PropertyAccessor.getProperty("gme.generate.default.context")); }
public void persist() { DataElementConcept dec = DomainObjectFactory.newDataElementConcept(); List<DataElementConcept> decs = elements.getElements(dec); logger.debug("***** Inside DEC Persist "); int count = 0; sendProgressEvent(count++, decs.size(), "DECs"); logger.debug("decs... "); if (decs != null) { for (ListIterator<DataElementConcept> it = decs.listIterator(); it.hasNext(); ) { DataElementConcept newDec = DomainObjectFactory.newDataElementConcept(); dec = it.next(); sendProgressEvent(count++, decs.size(), "DEC : " + dec.getLongName()); List<AlternateName> passedAltNames = new ArrayList<AlternateName>(); for (AlternateName _an : dec.getAlternateNames()) passedAltNames.add(_an); List<Definition> modelDefinitions = new ArrayList<Definition>(); for (Definition _def : dec.getDefinitions()) modelDefinitions.add(_def); List<AdminComponentClassSchemeClassSchemeItem> passedACCSCSI = dec.getAcCsCsis(); dec.removeDefinitions(); dec.removeAlternateNames(); if (!StringUtil.isEmpty(dec.getPublicId()) && dec.getVersion() != null) { newDec = existingMapping(dec); dec.setId(newDec.getId()); for (AlternateName _an : passedAltNames) { persisterUtil.addAlternateName(dec, _an); } it.set(newDec); persisterUtil.addPackageClassification(dec); logger.info(PropertyAccessor.getProperty("mapped.to.existing.dec")); continue; } // update object class with persisted one if (dec.getObjectClass().getPublicId() == null) dec.setObjectClass(LookupUtil.lookupObjectClass(dec.getObjectClass().getPreferredName())); else dec.setObjectClass( LookupUtil.lookupObjectClass( dec.getObjectClass().getPublicId(), dec.getObjectClass().getVersion())); newDec.setObjectClass(dec.getObjectClass()); // update property with persisted one if (dec.getProperty().getPublicId() == null) dec.setProperty(LookupUtil.lookupProperty(dec.getProperty().getPreferredName())); else dec.setProperty( LookupUtil.lookupProperty( dec.getProperty().getPublicId(), dec.getProperty().getVersion())); newDec.setProperty(dec.getProperty()); logger.debug("dec name: " + dec.getLongName()); // logger.debug("alt Name: " + ne); List<String> eager = new ArrayList<String>(); eager.add("definitions"); // does this dec exist? List l = dataElementConceptDAO.find(newDec, eager); logger.debug("***** decs size : " + l.size()); if (l.size() == 0) { logger.debug("***** one or more decs "); if (dec.getConceptualDomain() == null) dec.setConceptualDomain(defaults.getConceptualDomain()); dec.setContext(defaults.getContext()); dec.setLongName( dec.getObjectClass().getLongName() + " " + dec.getProperty().getLongName()); dec.setPreferredDefinition( dec.getObjectClass().getPreferredDefinition() + DEC_PREFERRED_DEF_CONCAT_CHAR + dec.getProperty().getPreferredDefinition()); dec.setPreferredName( ConventionUtil.publicIdVersion(dec.getObjectClass()) + DEC_PREFERRED_NAME_CONCAT_CHAR + ConventionUtil.publicIdVersion(dec.getProperty())); dec.setVersion(new Float(1.0f)); dec.setWorkflowStatus(defaults.getWorkflowStatus()); dec.setProperty(LookupUtil.lookupProperty(dec.getProperty().getPreferredName())); dec.setAudit(defaults.getAudit()); dec.setLifecycle(defaults.getLifecycle()); StringBuilder builder = new StringBuilder(); for (char currentChar : dec.getPreferredDefinition().toCharArray()) { Character replacementChar = charReplacementMap.get(currentChar); builder.append(replacementChar != null ? replacementChar : currentChar); } dec.setPreferredDefinition(builder.toString()); logger.debug( "***** preferred name " + dec.getPreferredName() + " public ID " + dec.getPublicId()); newDec = dataElementConceptDAO.create(dec); logger.info(PropertyAccessor.getProperty("created.dec")); } else { newDec = (DataElementConcept) l.get(0); logger.info(PropertyAccessor.getProperty("existed.dec")); /* if DEC alreay exists, check context * If context is different, add Used_by alt_name */ dec.setId(newDec.getId()); if (!newDec.getContext().getId().equals(defaults.getContext().getId())) { AlternateName _an = DomainObjectFactory.newAlternateName(); _an.setName(defaults.getContext().getName()); _an.setType(AlternateName.TYPE_USED_BY); persisterUtil.addAlternateName(dec, _an); } } dec.setId(newDec.getId()); for (AlternateName _an : passedAltNames) { persisterUtil.addAlternateName(dec, _an); } for (Definition def : modelDefinitions) { persisterUtil.addAlternateDefinition(dec, def); } LogUtil.logAc(newDec, logger); logger.info("-- Public ID: " + newDec.getPublicId()); logger.info( PropertyAccessor.getProperty("oc.longName", newDec.getObjectClass().getLongName())); logger.info( PropertyAccessor.getProperty("prop.longName", newDec.getProperty().getLongName())); dec.setAcCsCsis(passedACCSCSI); persisterUtil.addPackageClassification(dec); it.set(newDec); // dec still referenced in DE. Need ID to retrieve it in DEPersister. dec.setId(newDec.getId()); } } logger.debug("***** End DEC persist"); }